ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-05-30 08:30:52
Exec Total Coverage
Lines: 3084 8675 35.6%
Functions: 80 300 26.7%
Branches: 2696 7674 35.1%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "dialog/info.h"
12 #include "metadata/metadata.h"
13
14 #include "base/qrs.h"
15 #include "base/dmap.h"
16 #include "base/packfile.h"
17 #include "base/cpool.h"
18 #include "base/autocombo.h"
19 #include "base/gui.h"
20 #include "base/msgstr.h"
21 #include "zc/zelda.h"
22 #include "zq/zq_class.h"
23 #include "zq/zq_misc.h"
24 #include "zq/zquest.h"
25 #include "base/qst.h"
26 #include "base/colors.h"
27 #include "tiles.h"
28 #include "base/zsys.h"
29 #include "sprite.h"
30 #include "items.h"
31 #include "zc/zc_sys.h"
32 #include "base/md5.h"
33 #include "hero_tiles.h"
34 #include "subscr.h"
35 #include "zq/zq_strings.h"
36 #include "zq/zq_subscr.h"
37 #include "zc/ffscript.h"
38 #include "base/util.h"
39 #include "zq/zq_files.h"
40 #include "dialog/alert.h"
41 #include "slopes.h"
42 #include "drawing.h"
43 #include "zinfo.h"
44 #include "zq/render_minimap.h"
45 #include "base/mapscr.h"
46 #include "iter.h"
47 #include <fmt/format.h>
48 #include <filesystem>
49
50 #ifdef __EMSCRIPTEN__
51 #include "base/emscripten_utils.h"
52 #endif
53
54 namespace fs = std::filesystem;
55
56 using namespace util;
57
58 extern uint8_t ViewLayer3BG, ViewLayer2BG;
59 extern int32_t LayerDitherBG, LayerDitherSz;
60 extern bool NoHighlightLayer0;
61
62 using std::string;
63 using std::pair;
64
65 #define COLOR_SOLID vc(4)
66 #define COLOR_SLOPE vc(13)
67 #define COLOR_LADDER vc(6)
68 //#define COLOR_EFFECT vc(10)
69
70 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
71 extern char msgbuf[MSG_NEW_SIZE*8];
72
73 extern string zScript;
74
75 12 zmap Map;
76 int32_t prv_mode=0;
77
78 bool save_warn=true;
79
80 int32_t COMBOPOS(int32_t x, int32_t y)
81 {
82 return (((y) & 0xF0) + ((x) >> 4));
83 }
84 int32_t COMBOPOS_B(int32_t x, int32_t y)
85 {
86 if(unsigned(x) >= 256 || unsigned(y) >= 176)
87 return -1;
88 return COMBOPOS(x,y);
89 }
90 int32_t COMBOX(int32_t pos)
91 {
92 return ((pos) % 16 * 16);
93 }
94 int32_t COMBOY(int32_t pos)
95 {
96 return ((pos) & 0xF0);
97 }
98
99 void reset_dmap(int32_t index)
100 {
101 bound(index,0,MAXDMAPS-1);
102 DMaps[index].clear();
103 DMaps[index].title = "";
104 sprintf(DMaps[index].intro, " ");
105 }
106
107 void reset_dmaps()
108 {
109 for(int32_t i=0; i<MAXDMAPS; i++)
110 reset_dmap(i);
111 }
112
113 void truncate_dmap_title(std::string& title)
114 {
115 title.resize(21, ' ');
116 }
117
118 mapscr* zmap::get_prvscr()
119 {
120 return &prvscr;
121 }
122
123
2/4
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 23 times.
23 zmap::zmap()
124 {
125 23 can_paste=false;
126 23 prv_cmbcycle=0;
127 23 prv_advance=0;
128 23 prv_freeze=0;
129 23 copyffc=-1;
130
131 23 memset(scrpos, 0, sizeof(scrpos));
132 23 memset(scrview, 0, sizeof(scrview));
133 23 screens=NULL;
134 23 prv_time=0;
135 23 prv_scr=0;
136 23 prv_map=0;
137 23 copyscr=0;
138 23 cursor={};
139 copymap=0;
140 layer_target_map = 0;
141 layer_target_scr = 0;
142 layer_target_multiple = 0;
143 }
144
145 11 void zmap::clear()
146 {
147
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
148 11 }
149 void zmap::force_refr_pointer()
150 {
151 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
152 screens = nullptr;
153 else screens = &TheMaps[cursor.map*MAPSCRS];
154 }
155 bool zmap::CanUndo()
156 {
157 return undo_stack.size() > 0;
158 }
159 bool zmap::CanRedo()
160 {
161 return redo_stack.size() > 0;
162 }
163 bool zmap::CanPaste()
164 {
165 return can_paste;
166 }
167 int32_t zmap::CopyScr()
168 {
169 return (copymap<<8)+copyscr;
170 }
171 int32_t zmap::getCopyFFC()
172 {
173 return copyffc;
174 }
175 set_ffc_command::data_t zmap::getCopyFFCData()
176 {
177 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
178 }
179 67 int32_t zmap::getMapCount()
180 {
181 67 return map_count;
182 }
183 int32_t zmap::getLayerTargetMap()
184 {
185 return layer_target_map;
186 }
187 int32_t zmap::getLayerTargetScr()
188 {
189 return layer_target_scr;
190 }
191 int32_t zmap::getLayerTargetMultiple()
192 {
193 return layer_target_multiple;
194 }
195 bool zmap::isDungeon(int32_t scr)
196 {
197 for(int32_t i=0; i<4; i++)
198 {
199 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
200 {
201 return false;
202 }
203 }
204
205 return true;
206 }
207
208 bool zmap::clearall(bool validate)
209 {
210 Color=0;
211 char tbuf[10];
212
213 if((header.templatepath[0]!=0)&&validate)
214 {
215 if(!valid_zqt(header.templatepath))
216 {
217 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
218 return false;
219 }
220 }
221
222 for(int32_t i=0; i<map_count; i++)
223 {
224 setCurrMap(i);
225 sprintf(tbuf, "%d", i);
226 clearmap(true);
227 }
228
229 setCurrMap(0);
230 return true;
231 }
232
233 bool zmap::reset_templates(bool validate)
234 {
235 //why are we doing this?
236 if(colordata==NULL)
237 {
238 return false;
239 }
240
241 //int32_t ret;
242 word version, build, dummy, sversion=0;
243 byte dummyc;
244 word dummyw;
245 //int32_t section_size;
246 word temp_map_count;
247 mapscr temp_mapscr;
248 PACKFILE *f=NULL;
249
250 // setPackfilePassword(datapwd);
251 f=open_quest_template(&header, "modules/classic/default.qst", validate);
252 get_version_and_build(f, &version, &build);
253
254 if(!find_section(f, ID_MAPS))
255 {
256 // setPackfilePassword(NULL);
257 return false;
258 }
259
260 //section version info
261 if(!p_igetw(&sversion,f))
262 {
263 return false;
264 }
265
266 if(!p_igetw(&dummy,f))
267 {
268 return false;
269 }
270
271 //section size
272 dword dummy_size;
273 if(!p_igetl(&dummy_size,f))
274 {
275 return false;
276 }
277
278 //finally... section data
279 if(!p_igetw(&temp_map_count,f))
280 {
281 return false;
282 }
283
284 if(version>12)
285 {
286 if(!p_getc(&dummyc,f))
287 return qe_invalid;
288
289 if(!p_getc(&dummyc,f))
290 return qe_invalid;
291
292 if(!p_igetw(&dummyw,f))
293 return qe_invalid;
294
295 if(!p_igetw(&dummyw,f))
296 return qe_invalid;
297
298 if(!p_igetw(&dummyw,f))
299 return qe_invalid;
300
301 if(!p_igetw(&dummyw,f))
302 return qe_invalid;
303
304 if(!p_igetw(&dummyw,f))
305 return qe_invalid;
306
307 if(!p_igetw(&dummyw,f))
308 return qe_invalid;
309
310 if(!p_igetw(&dummyw,f))
311 return qe_invalid;
312
313 if(!p_igetw(&dummyw,f))
314 return qe_invalid;
315
316 if(!p_igetw(&dummyw,f))
317 return qe_invalid;
318
319 if(!p_igetw(&dummyw,f))
320 return qe_invalid;
321
322 if(!p_getc(&dummyc,f))
323 return qe_invalid;
324
325 if(!p_getc(&dummyc,f))
326 return qe_invalid;
327 }
328
329 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
330 {
331 readmapscreen(f, &header, &temp_mapscr, sversion);
332 }
333
334 readmapscreen(f, &header, &TheMaps[128], sversion);
335 readmapscreen(f, &header, &TheMaps[129], sversion);
336
337 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
338 {
339 readmapscreen(f, &header, &temp_mapscr, sversion);
340 }
341
342 if(version>12)
343 {
344 if(!p_getc(&dummyc,f))
345 return qe_invalid;
346
347 if(!p_getc(&dummyc,f))
348 return qe_invalid;
349
350 if(!p_igetw(&dummyw,f))
351 return qe_invalid;
352
353 if(!p_igetw(&dummyw,f))
354 return qe_invalid;
355
356 if(!p_igetw(&dummyw,f))
357 return qe_invalid;
358
359 if(!p_igetw(&dummyw,f))
360 return qe_invalid;
361
362 if(!p_igetw(&dummyw,f))
363 return qe_invalid;
364
365 if(!p_igetw(&dummyw,f))
366 return qe_invalid;
367
368 if(!p_igetw(&dummyw,f))
369 return qe_invalid;
370
371 if(!p_igetw(&dummyw,f))
372 return qe_invalid;
373
374 if(!p_igetw(&dummyw,f))
375 return qe_invalid;
376
377 if(!p_igetw(&dummyw,f))
378 return qe_invalid;
379
380 if(!p_getc(&dummyc,f))
381 return qe_invalid;
382
383 if(!p_getc(&dummyc,f))
384 return qe_invalid;
385 }
386
387 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
388 {
389 readmapscreen(f, &header, &temp_mapscr, sversion);
390 }
391
392 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
393 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
394
395 pack_fclose(f);
396 clear_quest_tmpfile();
397
398 return true;
399 }
400
401 bool zmap::clearmap(bool newquest)
402 {
403 if(cursor.map<map_count)
404 {
405 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
406 {
407 clearscr(i);
408 }
409
410 setCurrScr(0);
411
412 if(newquest)
413 {
414 if(!reset_templates(false))
415 {
416 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
417 }
418 }
419 }
420
421 return true;
422 }
423
424 MapCursor zmap::getCursor() const
425 {
426 return cursor;
427 }
428
429 void zmap::setCursor(MapCursor new_cursor)
430 {
431 if (cursor == new_cursor)
432 return;
433
434 optional<int> oldcolor;
435 if (screens)
436 oldcolor = getcolor();
437
438 cursor = new_cursor;
439
440 int newcolor = getcolor();
441 loadlvlpal(newcolor);
442 if (!oldcolor || *oldcolor != newcolor)
443 rebuild_trans_table();
444
445 reset_combo_animations2();
446 mmap_mark_dirty();
447 regions_mark_dirty();
448 refresh(rALL);
449 }
450
451 bool zmap::isValidPosition(ComboPosition pos) const
452 {
453 return pos.is_valid(cursor);
454 }
455
456 int zmap::getScreenForPosition(ComboPosition pos) const
457 {
458 return cursor.viewscr + pos.screen_offset();
459 }
460
461 mapscr* zmap::CurrScr()
462 {
463 return screens+cursor.screen;
464 }
465 mapscr* zmap::Scr(int32_t scr)
466 {
467 return screens+scr;
468 }
469 mapscr* zmap::Scr(ComboPosition pos)
470 {
471 if (!pos.is_valid(cursor))
472 return nullptr;
473
474 int screen_offset = pos.screen_offset();
475 int screen = cursor.viewscr + screen_offset;
476 return AbsoluteScr(cursor.map, screen);
477 }
478 mapscr* zmap::Scr(ComboPosition pos, int layer)
479 {
480 int map = cursor.map;
481 int screen = cursor.viewscr + pos.screen_offset();
482 if (layer)
483 {
484 mapscr* scr = Map.AbsoluteScr(map, screen);
485 map = scr->layermap[CurrentLayer-1]-1;
486 screen = scr->layerscreen[CurrentLayer-1];
487 }
488
489 return AbsoluteScr(map, screen);
490 }
491 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
492 {
493 mapscr* scr = Scr(pos, layer);
494 if (scr && !(scr->valid&mVALID))
495 {
496 scr->valid |= mVALID;
497 setcolor(Color, scr);
498 }
499 return scr;
500 }
501 mapscr* zmap::AbsoluteScr(int32_t scr)
502 {
503 if(unsigned(scr) >= MAPSCRS*getMapCount())
504 return nullptr;
505 return &TheMaps[scr];
506 }
507 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
508 {
509 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
510 return nullptr;
511 return AbsoluteScr((map*MAPSCRS)+scr);
512 }
513 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
514 {
515 mapscr* scr = AbsoluteScr(map, screen);
516 if (scr && !(scr->valid&mVALID))
517 {
518 scr->valid |= mVALID;
519 setcolor(Color, scr);
520 }
521 return scr;
522 }
523 void zmap::set_prvscr(int32_t map, int32_t scr)
524 {
525 prvscr=TheMaps[(map*MAPSCRS)+scr];
526
527 for(int32_t i=0; i<6; i++)
528 {
529 if(prvscr.layermap[i]>0)
530 {
531 prvlayers[i]=TheMaps[(prvscr.layermap[i]-1)*MAPSCRS+prvscr.layerscreen[i]];
532 }
533 else
534 prvlayers[i].valid = 0;
535 }
536
537 prv_map=map;
538 prv_scr=scr;
539 }
540 92 int32_t zmap::getCurrMap()
541 {
542 92 return cursor.map;
543 }
544 22 void zmap::regions_mark_dirty()
545 {
546 22 regions_dirty = true;
547 22 }
548 void zmap::regions_refresh()
549 {
550 if (!regions_dirty)
551 return;
552
553 regions_dirty = false;
554 region_descriptions.clear();
555
556 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
557 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
558 region_descriptions.clear();
559 }
560 const std::vector<region_description>& zmap::get_region_descriptions()
561 {
562 regions_refresh();
563 return region_descriptions;
564 }
565 bool zmap::is_region(int screen)
566 {
567 if (screen < 0 || screen >= 128)
568 return false;
569
570 regions_refresh();
571 return current_map_region_ids[screen];
572 }
573 bool zmap::isDark(int scr)
574 {
575 return (screens[scr].flags&fDARK)!=0;
576 }
577 bool zmap::isValid(int32_t scr)
578 {
579 return (screens[scr].valid&mVALID)!=0;
580 }
581 bool zmap::isValid(int32_t map, int32_t scr)
582 {
583 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
584 }
585
586 11 void zmap::setCurrMap(int32_t index)
587 {
588 11 optional<int> oldcolor;
589
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(screens)
590 oldcolor = getcolor();
591 11 scrpos[cursor.map] = cursor.screen;
592 11 scrview[cursor.map] = cursor.viewscr;
593 11 cursor.map = bound(index,0,map_count);
594 11 screens = &TheMaps[cursor.map*MAPSCRS];
595
596 11 cursor.viewscr = scrview[cursor.map];
597 11 cursor.setScreen(scrpos[cursor.map]);
598
599 11 int newcolor = getcolor();
600 11 loadlvlpal(newcolor);
601
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if(!oldcolor || *oldcolor != newcolor)
602 11 rebuild_trans_table();
603
604 11 reset_combo_animations2();
605 11 mmap_mark_dirty();
606 11 regions_mark_dirty();
607 11 }
608
609 20 int32_t zmap::getCurrScr()
610 {
611 20 return cursor.screen;
612 }
613 11 void zmap::setCurrScr(int32_t scr)
614 {
615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (scr == cursor.screen)
616 return;
617
618 11 int32_t oldcolor=getcolor();
619 11 cursor.setScreen(scr);
620
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!(screens[cursor.screen].valid&mVALID))
621 {
622 oldcolor=-1;
623 }
624
625 11 int32_t newcolor=getcolor();
626 11 loadlvlpal(newcolor);
627
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
11 if (newcolor!=oldcolor)
628 {
629 10 rebuild_trans_table();
630 10 }
631
632 11 reset_combo_animations2();
633 11 setlayertarget();
634 11 mmap_mark_dirty();
635 11 regions_mark_dirty();
636 11 }
637
638 int32_t zmap::getViewScr()
639 {
640 return cursor.viewscr;
641 }
642
643 11 void zmap::setViewSize(int32_t size)
644 {
645 11 cursor.setSize(size);
646 11 }
647
648 8 int32_t zmap::getViewSize()
649 {
650 8 return cursor.size;
651 }
652
653 11 void zmap::setlayertarget()
654 {
655 11 layer_target_map = 0;
656 11 layer_target_multiple = 0;
657
658
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 11 times.
67 for(int32_t m=0; m<getMapCount(); ++m)
659 {
660
2/2
✓ Branch 0 taken 7616 times.
✓ Branch 1 taken 56 times.
7672 for(int32_t s=0; s<MAPSCRS; ++s)
661 {
662 7616 int32_t i=(m*MAPSCRS+s);
663 7616 mapscr *ts=&TheMaps[i];
664
665 // Search through each layer
666
2/2
✓ Branch 0 taken 45696 times.
✓ Branch 1 taken 7616 times.
53312 for(int32_t w=0; w<6; ++w)
667 {
668
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 45679 times.
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
45696 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
669 {
670 if(layer_target_map > 0)
671 {
672 layer_target_multiple += 1;
673 continue;
674 }
675
676 layer_target_map = m+1;
677 layer_target_scr = s;
678 }
679 45696 }
680 7616 }
681 56 }
682 11 }
683
684 void zmap::setcolor(int color, mapscr* scr)
685 {
686 if (!scr) scr = CurrScr();
687 scr->valid |= mVALID;
688 scr->color = color;
689
690 if(Color!=color)
691 {
692 Color = color;
693 loadlvlpal(color);
694 rebuild_trans_table();
695 }
696
697 mmap_mark_dirty();
698 }
699
700 33 int32_t zmap::getcolor()
701 {
702
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
33 if(prv_mode)
703 {
704 return prvscr.color;
705 }
706
707 33 return screens[cursor.screen].color;
708 33 }
709
710 void zmap::resetflags()
711 {
712 byte *di=&(screens[cursor.screen].valid);
713
714 for(int32_t i=1; i<48; i++)
715 {
716 *(di+i)=0;
717 }
718 }
719
720 word zmap::tcmbdat(int32_t pos)
721 {
722 return screens[TEMPLATE].data[pos];
723 }
724
725 word zmap::tcmbcset(int32_t pos)
726 {
727 return screens[TEMPLATE].cset[pos];
728 }
729
730 int32_t zmap::tcmbflag(int32_t pos)
731 {
732 return screens[TEMPLATE].sflag[pos];
733 }
734
735 word zmap::tcmbdat2(int32_t pos)
736 {
737 return screens[TEMPLATE2].data[pos];
738 }
739
740 word zmap::tcmbcset2(int32_t pos)
741 {
742 return screens[TEMPLATE2].cset[pos];
743 }
744
745 int32_t zmap::tcmbflag2(int32_t pos)
746 {
747 return screens[TEMPLATE2].sflag[pos];
748 }
749
750 void zmap::TemplateAll()
751 {
752 StartListCommand();
753 for(int32_t i=0; i<128; i++)
754 {
755 if((screens[i].valid&mVALID) && isDungeon(i))
756 DoTemplateCommand(-1, -1, i);
757 }
758 FinishListCommand();
759 }
760
761 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
762 {
763 if(scr==TEMPLATE)
764 return;
765
766 if(!(screens[scr].valid&mVALID))
767 screens[scr].color=Color;
768
769 screens[scr].valid|=mVALID;
770
771 for(int32_t i=0; i<32; i++)
772 {
773 screens[scr].data[i]=screens[TEMPLATE].data[i];
774 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
775 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
776 }
777
778 for(int32_t i=144; i<176; i++)
779 {
780 screens[scr].data[i]=screens[TEMPLATE].data[i];
781 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
782 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
783 }
784
785 for(int32_t y=2; y<=9; y++)
786 {
787 int32_t j=y<<4;
788 screens[scr].data[j]=screens[TEMPLATE].data[j];
789 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
790 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
791 ++j;
792 screens[scr].data[j]=screens[TEMPLATE].data[j];
793 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
794 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
795 ++j;
796 j+=12;
797 screens[scr].data[j]=screens[TEMPLATE].data[j];
798 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
799 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
800 ++j;
801 screens[scr].data[j]=screens[TEMPLATE].data[j];
802 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
803
804 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
805 ++j;
806 }
807
808 if(floorcombo!=-1)
809 {
810 for(int32_t y=2; y<9; y++)
811 for(int32_t x=2; x<14; x++)
812 {
813 int32_t i=(y<<4)+x;
814 screens[scr].data[i] = floorcombo;
815 screens[scr].cset[i] = floorcset;
816 }
817 }
818
819 for(int32_t i=0; i<4; i++)
820 putdoor(scr,i,screens[scr].door[i]);
821 }
822
823
824 void zmap::clearscr(int32_t scr)
825 {
826 screens[scr].zero_memory();
827 screens[scr].valid=mVERSION;
828 for(int q = 0; q < 6; ++q)
829 {
830 auto layer = map_autolayers[cursor.map*6+q];
831 screens[scr].layermap[q] = layer;
832 screens[scr].layerscreen[q] = layer ? scr : 0;
833 }
834 mmap_mark_dirty();
835 }
836
837 const char *loaderror[] =
838 {
839
840 "OK","File not found","Incomplete data",
841 "Invalid version","Invalid file"
842
843 };
844
845 int32_t zmap::load(const char *path)
846 {
847 PACKFILE *f=pack_fopen_password(path,F_READ, "");
848
849 if(!f)
850 return 1;
851
852
853 int16_t version;
854 byte build;
855
856 //get the version
857 if(!p_igetw(&version,f))
858 {
859 goto file_error;
860 }
861
862 //get the build
863 if(!p_getc(&build,f))
864 {
865 goto file_error;
866 }
867
868 for(int32_t i=0; i<MAPSCRS; i++)
869 {
870 mapscr tmpimportscr;
871 tmpimportscr.zero_memory();
872 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
873 {
874 al_trace("failed zmap::load\n");
875 goto file_error;
876 }
877
878 switch(ImportMapBias)
879 {
880 case 0:
881 *(screens+i) = tmpimportscr;
882 break;
883
884 case 1:
885 if(!(screens[i].valid&mVALID))
886 {
887 *(screens+i) = tmpimportscr;
888 }
889 break;
890
891 case 2:
892 if(tmpimportscr.valid&mVALID)
893 {
894 *(screens+i) = tmpimportscr;
895 }
896 break;
897 }
898 }
899
900
901 pack_fclose(f);
902
903 setCurrScr(0);
904 mmap_mark_dirty();
905 regions_mark_dirty();
906 return 0;
907
908 file_error:
909 pack_fclose(f);
910 clearmap(false);
911 return 2;
912 }
913
914 int32_t zmap::save(const char *path)
915 {
916 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
917
918 if(!f)
919 return 1;
920
921 if(!p_iputw(V_MAPS,f))
922 {
923 pack_fclose(f);
924 return 3;
925 }
926
927 // This was the "build number", but that's totally useless here. Keep this junk byte
928 // so as not to totally break exports between ZC versions.
929 if(!p_putc(0,f))
930 {
931 pack_fclose(f);
932 return 3;
933 }
934
935 for(int32_t i=0; i<MAPSCRS; i++)
936 {
937 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
938 {
939 pack_fclose(f);
940 return 2;
941 }
942 }
943
944 pack_fclose(f);
945 return 0;
946 }
947
948
949 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
950 {
951 // Hookshots can be blocked by solid combos on all 3 ground layers.
952 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
953
954 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
955 return true;
956 if (c->walk&(1<<i))
957 return false;
958
959 for(int32_t k=0; k<2; k++)
960 {
961 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
962
963 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
964 {
965 return false;
966 }
967 }
968
969 return true;
970 }
971
972 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
973 {
974 // Hookshots can be blocked by solid combos on all 3 ground layers.
975 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
976
977 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
978 return true;
979 if (c->walk&(1<<i))
980 return false;
981
982 for(int32_t k=0; k<2; k++)
983 {
984 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
985
986 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
987 {
988 return false;
989 }
990 }
991
992 return true;
993 }
994
995 bool zmap::isstepable(int32_t combo)
996 {
997 // This is kind of odd but it's true to the engine (see maps.cpp)
998 return (combo_class_buf[combobuf[combo].type].ladder_pass);
999 }
1000
1001 // Returns the letter of the warp combo.
1002 int32_t zmap::warpindex(int32_t combo)
1003 {
1004 switch(combobuf[combo].type)
1005 {
1006 case cCAVE:
1007 case cPIT:
1008 case cSTAIR:
1009 case cCAVE2:
1010 case cSWIMWARP:
1011 case cDIVEWARP:
1012 case cSWARPA:
1013 return 0;
1014
1015 case cCAVEB:
1016 case cPITB:
1017 case cSTAIRB:
1018 case cCAVE2B:
1019 case cSWIMWARPB:
1020 case cDIVEWARPB:
1021 case cSWARPB:
1022 return 1;
1023
1024 case cCAVEC:
1025 case cPITC:
1026 case cSTAIRC:
1027 case cCAVE2C:
1028 case cSWIMWARPC:
1029 case cDIVEWARPC:
1030 case cSWARPC:
1031 return 2;
1032
1033 case cCAVED:
1034 case cPITD:
1035 case cSTAIRD:
1036 case cCAVE2D:
1037 case cSWIMWARPD:
1038 case cDIVEWARPD:
1039 case cSWARPD:
1040 return 3;
1041
1042 case cPITR:
1043 case cSTAIRR:
1044 case cSWARPR:
1045 return 4;
1046 }
1047
1048 return -1;
1049
1050 }
1051
1052 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1053 {
1054 if(top)
1055 line(dest,x,y,x+15,y,c);
1056 rectfill(dest,x,y,x+3,y+15,c);
1057 rectfill(dest,x+12,y,x+15,y+15,c);
1058 rectfill(dest,x+4,y+2,x+11,y+5,c);
1059 rectfill(dest,x+4,y+10,x+11,y+13,c);
1060 }
1061
1062 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1063 {
1064 line(dest,x,y,x+15,y,c);
1065 }
1066
1067 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1068 {
1069 int32_t cx = COMBOX(pos);
1070 int32_t cy = COMBOY(pos);
1071
1072 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1073
1074 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1075
1076 int32_t bridgedetected = 0;
1077
1078 for(int32_t i=0; i<4; i++)
1079 {
1080 int32_t tx=((i&2)<<2)+x;
1081 int32_t ty=((i&1)<<3)+y;
1082 int32_t tx2=((i&2)<<2)+cx;
1083 int32_t ty2=((i&1)<<3)+cy;
1084 for (int32_t m = layer; m <= 1; m++)
1085 {
1086 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1087 {
1088 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1089 {
1090 bridgedetected |= (1<<i);
1091 }
1092 }
1093 else
1094 {
1095 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1096 {
1097 bridgedetected |= (1<<i);
1098 }
1099 }
1100 }
1101 if (bridgedetected & (1<<i))
1102 {
1103 if (i >= 3) break;
1104 else continue;
1105 }
1106 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1107 {
1108 for(int32_t k=0; k<8; k+=2)
1109 for(int32_t j=0; j<8; j+=2)
1110 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1111 }
1112 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1113 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1114
1115 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1116 {
1117 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1118 {
1119 for(int32_t k=0; k<8; k+=2)
1120 for(int32_t j=0; j<8; j+=2)
1121 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1122 }
1123 else
1124 {
1125 int32_t color = COLOR_SOLID;
1126
1127 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1128 color=vc(6);
1129 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1130 color=vc(7);
1131
1132 rectfill(dest,tx,ty,tx+7,ty+7,color);
1133 }
1134 }
1135 }
1136
1137 bridgedetected = 0;
1138 for(int32_t i=0; i<4; i++)
1139 {
1140 int32_t tx2=((i&2)<<2)+cx;
1141 int32_t ty2=((i&1)<<3)+cy;
1142 for (int32_t m = 0; m <= 1; m++)
1143 {
1144 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1145 {
1146 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1147 {
1148 bridgedetected |= (1<<i);
1149 }
1150 }
1151 else
1152 {
1153 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1154 {
1155 bridgedetected |= (1<<i);
1156 }
1157 }
1158 }
1159 }
1160
1161 // Draw damage combos
1162 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1163 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1164 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1165 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1166 || combo_class_buf[c1.type].modify_hp_amount
1167 || combo_class_buf[c2.type].modify_hp_amount;
1168
1169 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1170
1171 if(dmg)
1172 {
1173 if (bridgedetected <= 0)
1174 {
1175 for(int32_t k=0; k<16; k+=2)
1176 for(int32_t j=0; j<16; j+=2)
1177 if(((k+j)/2)%2)
1178 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1179 }
1180 else
1181 {
1182 for(int32_t i=0; i<4; i++)
1183 {
1184 if (!(bridgedetected & (1<<i)))
1185 {
1186 int32_t tx=((i&2)<<2)+x;
1187 int32_t ty=((i&1)<<3)+y;
1188 for(int32_t k=0; k<8; k+=2)
1189 for(int32_t j=0; j<8; j+=2)
1190 if(((k+j)/2)%2)
1191 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1192 }
1193 }
1194 }
1195 }
1196
1197 if(c.type == cSLOPE)
1198 {
1199 slope_info s(c, x, y);
1200 s.draw(dest, 0, 0, COLOR_SLOPE);
1201 }
1202 auto fl0 = MAPFLAG2(-1,cx,cy);
1203 auto fl1 = MAPFLAG2(0,cx,cy);
1204 auto fl2 = MAPFLAG2(1,cx,cy);
1205 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1206 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1207 {
1208 bool top = false;
1209 if(cy)
1210 {
1211 top = true;
1212 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1213 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1214 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1215 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1216 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1217 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1218 {
1219 top = false;
1220 }
1221 }
1222 draw_ladder(dest,x,y,COLOR_LADDER,top);
1223 }
1224 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1225 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1226 {
1227 draw_platform(dest,x,y,COLOR_LADDER);
1228 }
1229 }
1230
1231 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1232 {
1233 int32_t cx = COMBOX(pos);
1234 int32_t cy = COMBOY(pos);
1235
1236 if (screen < 0) return;
1237 if (map < 0) return;
1238
1239 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1240
1241 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1242
1243 int32_t bridgedetected = 0;
1244 for(int32_t i=0; i<4; i++)
1245 {
1246 int32_t tx=((i&2)<<2)+x;
1247 int32_t ty=((i&1)<<3)+y;
1248 int32_t tx2=((i&2)<<2)+cx;
1249 int32_t ty2=((i&1)<<3)+cy;
1250 for (int32_t m = layer; m <= 1; m++)
1251 {
1252 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1253 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1254 {
1255 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1256 {
1257 bridgedetected |= (1<<i);
1258 }
1259 }
1260 else
1261 {
1262 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1263 {
1264 bridgedetected |= (1<<i);
1265 }
1266 }
1267 }
1268 if (bridgedetected & (1<<i))
1269 {
1270 continue;
1271 }
1272 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1273 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1274
1275
1276 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1277 {
1278 for(int32_t k=0; k<8; k+=2)
1279 for(int32_t j=0; j<8; j+=2)
1280 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1281 }
1282 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1283 {
1284 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1285 {
1286 for(int32_t k=0; k<8; k+=2)
1287 for(int32_t j=0; j<8; j+=2)
1288 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1289 }
1290 else
1291 {
1292 int32_t color = COLOR_SOLID;
1293
1294 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1295 color=vc(6);
1296 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1297 color=vc(7);
1298
1299 rectfill(dest,tx,ty,tx+7,ty+7,color);
1300 }
1301 }
1302 }
1303
1304 bridgedetected = 0;
1305 for(int32_t i=0; i<4; i++)
1306 {
1307 int32_t tx2=((i&2)<<2)+cx;
1308 int32_t ty2=((i&1)<<3)+cy;
1309 for (int32_t m = 0; m <= 1; m++)
1310 {
1311 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1312 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1313 {
1314 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1315 {
1316 bridgedetected |= (1<<i);
1317 }
1318 }
1319 else
1320 {
1321 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1322 {
1323 bridgedetected |= (1<<i);
1324 }
1325 }
1326 }
1327 }
1328
1329 // Draw damage combos
1330 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1331 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1332 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1333 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1334 || combo_class_buf[c1.type].modify_hp_amount
1335 || combo_class_buf[c2.type].modify_hp_amount;
1336
1337 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1338
1339 if(dmg)
1340 {
1341 if (bridgedetected <= 0)
1342 {
1343 for(int32_t k=0; k<16; k+=2)
1344 for(int32_t j=0; j<16; j+=2)
1345 if(((k+j)/2)%2)
1346 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1347 }
1348 else
1349 {
1350 for(int32_t i=0; i<4; i++)
1351 {
1352 if (!(bridgedetected & (1<<i)))
1353 {
1354 int32_t tx=((i&2)<<2)+x;
1355 int32_t ty=((i&1)<<3)+y;
1356 for(int32_t k=0; k<8; k+=2)
1357 for(int32_t j=0; j<8; j+=2)
1358 if(((k+j)/2)%2)
1359 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1360 }
1361 }
1362 }
1363 }
1364
1365 if(c.type == cSLOPE)
1366 {
1367 slope_info s(c, x, y);
1368 s.draw(dest, 0, 0, COLOR_SLOPE);
1369 }
1370 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1371 auto fl1 = MAPFLAG3(map,screen,0,pos);
1372 auto fl2 = MAPFLAG3(map,screen,1,pos);
1373 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1374 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1375 {
1376 bool top = false;
1377 if(cy)
1378 {
1379 top = true;
1380 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1381 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1382 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1383 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1384 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1385 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1386 {
1387 top = false;
1388 }
1389 }
1390 draw_ladder(dest,x,y,COLOR_LADDER,top);
1391 }
1392 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1393 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1394 {
1395 draw_platform(dest,x,y,COLOR_LADDER);
1396 }
1397 }
1398
1399 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1400 {
1401 const newcombo& c = combobuf[cmbdat];
1402
1403 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1404
1405 for(int32_t i=0; i<4; i++)
1406 {
1407 int32_t tx=((i&2)<<2)+x;
1408 int32_t ty=((i&1)<<3)+y;
1409
1410 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1411 {
1412 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1413 {
1414 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1415 }
1416 else
1417 {
1418 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1419 }
1420 }
1421
1422
1423 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1424 {
1425 for(int32_t k=0; k<8; k+=2)
1426 for(int32_t j=0; j<8; j+=2)
1427 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1428 }
1429 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1430 {
1431 if(c.type==cLADDERHOOKSHOT)
1432 {
1433 for(int32_t k=0; k<8; k+=2)
1434 for(int32_t j=0; j<8; j+=2)
1435 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1436 }
1437 else
1438 {
1439 int32_t color = COLOR_SOLID;
1440
1441 if(c.type==cLADDERONLY)
1442 color=vc(6);
1443 else if(c.type==cHOOKSHOTONLY)
1444 color=vc(7);
1445
1446 rectfill(dest,tx,ty,tx+7,ty+7,color);
1447 }
1448 }
1449
1450 // Draw damage combos
1451 if(combo_class_buf[c.type].modify_hp_amount != 0)
1452 {
1453 for(int32_t k=0; k<8; k+=2)
1454 for(int32_t j=0; j<8; j+=2)
1455 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1456 }
1457 }
1458
1459 if(c.type == cSLOPE)
1460 {
1461 slope_info s(c, 0, 0);
1462 zfix const& slope = s.slope();
1463
1464 BITMAP* sub = create_bitmap_ex(8,16,16);
1465 clear_bitmap(sub);
1466 s.draw(sub, 0, 0, COLOR_SLOPE);
1467 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1468 destroy_bitmap(sub);
1469 }
1470 if(c.flag == mfSIDEVIEWLADDER)
1471 {
1472 draw_ladder(dest,x,y,COLOR_LADDER);
1473 }
1474 else if(c.flag == mfSIDEVIEWPLATFORM)
1475 {
1476 draw_platform(dest,x,y,COLOR_LADDER);
1477 }
1478 }
1479
1480 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1481 {
1482 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1483 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1484 }
1485 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1486 {
1487
1488 newcombo const& c = combobuf[cmbdat];
1489
1490 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1491 {
1492 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1493 // text_mode(-1);
1494 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1495 if(sflag)
1496 {
1497 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1498 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1499 }
1500
1501 if(c.flag)
1502 {
1503 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1504 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1505 }
1506 }
1507
1508 if(flags&cCSET)
1509 {
1510 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1511 // text_mode(inv?vc(15):vc(0));
1512 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1513 }
1514 else if(flags&cCTYPE)
1515 {
1516 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1517 // text_mode(inv?vc(15):vc(0));
1518 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1519 }
1520 }
1521
1522 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1523 {
1524 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1525
1526 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1527 if(repos)
1528 {
1529 combotile_override_x = x+(8*(scale-1));
1530 combotile_override_y = y+(8*(scale-1));
1531 }
1532 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1533 if(repos) combotile_override_x = combotile_override_y = -1;
1534 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1535 destroy_bitmap(b);
1536 }
1537 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1538 {
1539 static newcombo nilcombo;
1540 nilcombo.tile = 0;
1541
1542 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1543
1544 if(c.tile==0)
1545 {
1546 rectfill(dest,x,y,x+15,y+15,vc(0));
1547 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1548 return;
1549 }
1550
1551 putcombo(dest,x,y,cmbdat,cset);
1552
1553 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1554 {
1555 if(sflag)
1556 {
1557 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1558 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1559 }
1560
1561 if(combobuf[cmbdat].flag)
1562 {
1563 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1564 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1565 }
1566 }
1567
1568 if(flags&cWALK)
1569 {
1570 put_walkflags(dest,x,y,cmbdat,0);
1571 }
1572
1573 if(flags&cCSET)
1574 {
1575 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1576 // text_mode(inv?vc(15):vc(0));
1577 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1578 }
1579 else if(flags&cCTYPE)
1580 {
1581 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1582 // text_mode(inv?vc(15):vc(0));
1583 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1584 }
1585 }
1586 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1587 {
1588 auto blitx = 1 + (slot % 16) * 17;
1589 auto blity = 1 + (slot / 16) * 17;
1590 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1591 }
1592
1593
1594 void copy_mapscr(mapscr *dest, const mapscr *src)
1595 {
1596 if(!dest || !src) return;
1597 *dest = *src;
1598 }
1599
1600 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1601 {
1602 int32_t x=0,y=0;
1603 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1604
1605 switch(side)
1606 {
1607 case up:
1608 case down:
1609 x=((pos&15)<<4)+xofs;
1610 y=(ignorepos?0:(pos&0xF0))+yofs;
1611 break;
1612
1613 case left:
1614 case right:
1615 x=(ignorepos?0:((pos&15)<<4))+xofs;
1616 y=(pos&0xF0)+yofs;
1617 break;
1618 }
1619
1620 switch(type)
1621 {
1622 case dt_lock:
1623 case dt_shut:
1624 case dt_boss:
1625 case dt_bomb:
1626 switch(side)
1627 {
1628 case up:
1629 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1630 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1631 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1632 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1633 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1635 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1636 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1637 break;
1638
1639 case down:
1640 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1641 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1642 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1643 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1644 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1646 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1647 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1648 break;
1649
1650 case left:
1651 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1652 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1653 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1654 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1655 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1656 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1657
1658 if(x+16 >= dest->w)
1659 break;
1660
1661 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1662 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1663 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1664 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1665 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1666 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1667 break;
1668
1669 case right:
1670
1671 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1672 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1673 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1674 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1675 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1676 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1677
1678 if(x+16 <= 0)
1679 break;
1680
1681 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1682 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1683 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1684 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1685 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1686 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1687 break;
1688 }
1689
1690 break;
1691
1692 case dt_pass:
1693 case dt_wall:
1694 case dt_walk:
1695 default:
1696 break;
1697 }
1698 }
1699
1700 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1701 {
1702 int32_t x=((pos&15)<<4)+xofs;
1703 int32_t y=(pos&0xF0)+yofs;
1704 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1705
1706
1707 switch(side)
1708 {
1709 case up:
1710 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1711 {
1712 overcombo(dest,x,y,
1713 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1714 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1715 }
1716
1717 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1718 {
1719 overcombo(dest,x+16,y,
1720 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1721
1722 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1723 }
1724
1725 break;
1726
1727 case down:
1728 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1729 {
1730 overcombo(dest,x,y,
1731 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1732 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1733 }
1734
1735 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1736 {
1737 overcombo(dest,x+16,y,
1738 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1739 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1740 }
1741
1742 break;
1743
1744 case left:
1745 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1746 {
1747 overcombo(dest,x,y,
1748 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1749 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1750 }
1751
1752 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1753 {
1754 overcombo(dest,x,y+16,
1755 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1756 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1757 }
1758
1759 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1760 {
1761 overcombo(dest,x,y+32,
1762 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1763 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1764 }
1765
1766 break;
1767
1768 case right:
1769 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1770 {
1771 overcombo(dest,x,y,
1772 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1773 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1774 }
1775
1776 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1777 {
1778 overcombo(dest,x,y+16,
1779
1780 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1781 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1782 }
1783
1784 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1785 {
1786 overcombo(dest,x,y+32,
1787 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1788 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1789 }
1790
1791 break;
1792 }
1793 }
1794
1795 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1796 {
1797 word cmbcheck1, cmbcheck2;
1798 newcombo combocheck1, combocheck2;
1799 combocheck1 = combobuf[0];
1800 combocheck2 = combobuf[0];
1801 combocheck1.walk = 0;
1802 combocheck2.walk = 0;
1803
1804 int32_t layermap, layerscreen;
1805
1806 switch(dir)
1807 {
1808 case up:
1809 {
1810 if(i>15) //not top row of combos
1811 {
1812 return false;
1813 }
1814
1815 if(screen<16) //top row of screens
1816 {
1817 return false;
1818
1819 }
1820
1821 //check main screen
1822 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1823 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1824 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1825 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1826
1827 //check layer 1
1828 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1829
1830 if(layermap>-1 && layermap<map_count)
1831 {
1832 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1833 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1834 if (combobuf[cmbcheck1].type == cBRIDGE)
1835 {
1836 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1837 {
1838 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1839 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1840 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1841 }
1842 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1843 }
1844 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1845 }
1846
1847 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1848
1849 if(layermap>-1 && layermap<map_count)
1850 {
1851 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1852 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1853 if (combobuf[cmbcheck2].type == cBRIDGE)
1854 {
1855 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1856 {
1857 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1858 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1859 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1860 }
1861 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1862 }
1863 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1864 }
1865
1866 //check layer 2
1867 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1868
1869 if(layermap>-1 && layermap<map_count)
1870 {
1871 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1872
1873 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1874 if (combobuf[cmbcheck2].type == cBRIDGE)
1875 {
1876 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1877 {
1878 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1879 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1880 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1881 }
1882 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1883 }
1884 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1885 }
1886
1887 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1888
1889 if(layermap>-1 && layermap<map_count)
1890 {
1891 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1892 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1893 if (combobuf[cmbcheck2].type == cBRIDGE)
1894 {
1895 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1896 {
1897 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1898 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1899 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1900 }
1901 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1902 }
1903 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1904 }
1905
1906 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1907 {
1908 return true;
1909 }
1910
1911 break;
1912 }
1913 case down:
1914 {
1915 if(i<160) //not bottom row of combos
1916 {
1917 return false;
1918 }
1919
1920 if(screen>111) //bottom row of screens
1921 {
1922 return false;
1923 }
1924
1925 //check main screen
1926 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1927 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1928 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1929 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1930
1931
1932 //check layer 1
1933 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1934
1935 if(layermap>-1 && layermap<map_count)
1936 {
1937 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1938 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1939 if (combobuf[cmbcheck1].type == cBRIDGE)
1940 {
1941 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1942 {
1943 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1944 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1945 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1946 }
1947 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1948 }
1949 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1950 }
1951
1952 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1953
1954 if(layermap>-1 && layermap<map_count)
1955 {
1956 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1957 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1958 if (combobuf[cmbcheck2].type == cBRIDGE)
1959 {
1960 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1961 {
1962 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1963 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1964 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1965 }
1966 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1967 }
1968 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1969 }
1970
1971 //check layer 2
1972 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1973
1974 if(layermap>-1 && layermap<map_count)
1975 {
1976 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1977 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1978 if (combobuf[cmbcheck1].type == cBRIDGE)
1979 {
1980 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1981 {
1982 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1983 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1984 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1985 }
1986 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1987 }
1988 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1989 }
1990
1991 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1992
1993 if(layermap>-1 && layermap<map_count)
1994 {
1995 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1996 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1997 if (combobuf[cmbcheck2].type == cBRIDGE)
1998 {
1999 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2000 {
2001 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2002 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2003 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2004 }
2005 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2006 }
2007 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2008 }
2009
2010 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2011 {
2012 return true;
2013 }
2014
2015 break;
2016 }
2017 case left:
2018 {
2019 if((i&0xF)!=0) //not left column of combos
2020 {
2021 return false;
2022 }
2023
2024 if((screen&0xF)==0) //left column of screens
2025 {
2026 return false;
2027 }
2028
2029 //check main screen
2030 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2031 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2032 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2033 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2034
2035 //check layer 1
2036 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2037
2038 if(layermap>-1 && layermap<map_count)
2039 {
2040 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2041 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2042 if (combobuf[cmbcheck1].type == cBRIDGE)
2043 {
2044 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2045 {
2046 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2047 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2048 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2049 }
2050 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2051 }
2052 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2053 }
2054
2055 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2056
2057 if(layermap>-1 && layermap<map_count)
2058 {
2059 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2060 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2061 if (combobuf[cmbcheck2].type == cBRIDGE)
2062 {
2063 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2064 {
2065 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2066 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2067 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2068 }
2069 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2070 }
2071 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2072 }
2073
2074 //check layer 2
2075 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2076
2077 if(layermap>-1 && layermap<map_count)
2078 {
2079 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2080 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2081 if (combobuf[cmbcheck1].type == cBRIDGE)
2082 {
2083 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2084 {
2085 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2086 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2087 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2088 }
2089 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2090 }
2091 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2092 }
2093
2094 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2095
2096 if(layermap>-1 && layermap<map_count)
2097 {
2098 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2099 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2100 if (combobuf[cmbcheck2].type == cBRIDGE)
2101 {
2102 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2103 {
2104 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2105 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2106 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2107 }
2108 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2109 }
2110 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2111 }
2112
2113 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2114 {
2115 return true;
2116 }
2117
2118 break;
2119 }
2120 case right:
2121 {
2122 if((i&0xF)!=15) //not right column of combos
2123 {
2124 return false;
2125 }
2126
2127 if((screen&0xF)==15) //right column of screens
2128 {
2129 return false;
2130 }
2131
2132 //check main screen
2133 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2134 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2135 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2136 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2137
2138 //check layer 1
2139 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2140
2141 if(layermap>-1 && layermap<map_count)
2142 {
2143 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2144 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2145 if (combobuf[cmbcheck1].type == cBRIDGE)
2146 {
2147 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2148 {
2149 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2150 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2151 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2152 }
2153 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2154 }
2155 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2156 }
2157
2158 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2159
2160 if(layermap>-1 && layermap<map_count)
2161 {
2162 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2163 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2164 if (combobuf[cmbcheck2].type == cBRIDGE)
2165 {
2166 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2167 {
2168 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2169 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2170 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2171 }
2172 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2173 }
2174 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2175 }
2176
2177 //check layer 2
2178 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2179
2180 if(layermap>-1 && layermap<map_count)
2181 {
2182 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2183 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2184 if (combobuf[cmbcheck1].type == cBRIDGE)
2185 {
2186 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2187 {
2188 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2189 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2190 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2191 }
2192 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2193 }
2194 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2195 }
2196
2197 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2198
2199 if(layermap>-1 && layermap<map_count)
2200 {
2201 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2202
2203 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2204 if (combobuf[cmbcheck2].type == cBRIDGE)
2205 {
2206 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2207 {
2208 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2209 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2210 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2211 }
2212 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2213 }
2214 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2215 }
2216
2217 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2218 {
2219 return true;
2220 }
2221
2222 break;
2223 }
2224 }
2225
2226 return false;
2227 }
2228
2229 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2230 {
2231 int32_t checkcombo;
2232
2233 if(alignment_arrow_timer>31)
2234 {
2235 if(scr<0)
2236 {
2237 scr=cursor.screen;
2238 }
2239
2240 if((scr<128)) //do the misalignment arrows
2241 {
2242 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2243 {
2244 if(misaligned(cursor.map, scr, checkcombo, up))
2245 {
2246 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2247 }
2248 }
2249
2250 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2251 {
2252 if(misaligned(cursor.map, scr, checkcombo, down))
2253 {
2254 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2255 }
2256 }
2257
2258 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2259 {
2260 if(misaligned(cursor.map, scr, checkcombo, left))
2261 {
2262 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2263 }
2264 }
2265
2266 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2267 {
2268 if(misaligned(cursor.map, scr, checkcombo, right))
2269 {
2270 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2271 }
2272 }
2273
2274 int32_t tempalign;
2275
2276 //check top left corner
2277 checkcombo=0;
2278 tempalign=0;
2279 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2280 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2281
2282 switch(tempalign)
2283 {
2284 case 0:
2285 break;
2286
2287 case 1: //up
2288 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2289 break;
2290
2291 case 2: //left
2292 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2293 break;
2294
2295 case 3: //up-left
2296 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2297 break;
2298 }
2299
2300 //check top right corner
2301 checkcombo=15;
2302 tempalign=0;
2303 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2304 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2305
2306 switch(tempalign)
2307 {
2308 case 0:
2309 break;
2310
2311 case 1: //up
2312 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2313 break;
2314
2315 case 2: //right
2316 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2317 break;
2318
2319 case 3: //up-right
2320 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2321 break;
2322 }
2323
2324 //check bottom left corner
2325 checkcombo=160;
2326 tempalign=0;
2327 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2328 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2329
2330 switch(tempalign)
2331 {
2332 case 0:
2333 break;
2334
2335 case 1: //down
2336 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2337 break;
2338
2339 case 2: //left
2340 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2341 break;
2342
2343 case 3: //down-left
2344 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2345 break;
2346 }
2347
2348 //check bottom right corner
2349
2350 checkcombo=175;
2351 tempalign=0;
2352 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2353 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2354
2355 switch(tempalign)
2356 {
2357 case 0:
2358 break;
2359
2360 case 1: //down
2361 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2362 break;
2363
2364 case 2: //right
2365 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2366 break;
2367
2368 case 3: //down-right
2369 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2370 break;
2371 }
2372 }
2373 }
2374 }
2375
2376 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2377 {
2378 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2379 }
2380
2381 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2382 {
2383 if (map < 0 || screen < 0) return 0;
2384
2385 if(pos>175 || pos < 0)
2386 return 0;
2387
2388 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2389
2390 if (!m->is_valid()) return 0;
2391
2392 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2393
2394 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2395
2396 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2397
2398 if (!scr->is_valid()) return 0;
2399
2400 return scr->data[pos]; // entire combo code
2401 }
2402
2403 // Takes array index layer num., not actual layer num.
2404 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2405 {
2406 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2407
2408 if(map<0)
2409 map=cursor.map;
2410
2411 if(scr<0)
2412 scr=cursor.screen;
2413
2414 mapscr *screen1;
2415
2416 if(prv_mode)
2417 {
2418 screen1=get_prvscr();
2419 }
2420 else
2421 {
2422 screen1=AbsoluteScr(cursor.map,cursor.screen);
2423 }
2424
2425 int32_t layermap;
2426 layermap=screen1->layermap[lyr]-1;
2427
2428 if(layermap<0 || layermap >= map_count) return 0;
2429
2430 mapscr *layer;
2431
2432 if(prv_mode)
2433 layer = &prvlayers[lyr];
2434 else
2435 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2436
2437 int32_t pos = COMBOPOS(x,y);
2438
2439 if(pos>175 || pos < 0)
2440 return 0;
2441
2442 return layer->data[pos];
2443 }
2444
2445 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2446 {
2447 if(map<0)
2448 map=cursor.map;
2449
2450 if(scr<0)
2451 scr=cursor.screen;
2452
2453 mapscr *screen1;
2454
2455 if(prv_mode)
2456 {
2457 screen1=get_prvscr();
2458 }
2459 else
2460 {
2461 screen1=AbsoluteScr(cursor.map,cursor.screen);
2462 }
2463
2464 x = vbound(x, 0, 16*16);
2465 y = vbound(y, 0, 11*16);
2466 int32_t combo = COMBOPOS(x,y);
2467
2468 if(combo>175 || combo < 0)
2469 return 0;
2470
2471 return screen1->data[combo];
2472 }
2473
2474 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2475 {
2476 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2477 }
2478
2479 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2480 {
2481 if (map < 0 || screen < 0) return 0;
2482
2483 if(pos>175 || pos < 0)
2484 return 0;
2485
2486 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2487
2488 if (!m->is_valid()) return 0;
2489
2490 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2491
2492 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2493
2494 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2495
2496 if (!scr->is_valid()) return 0;
2497
2498 return scr->sflag[pos]; // entire combo code
2499 }
2500
2501 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2502 {
2503 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2504
2505 if(map<0)
2506 map=cursor.map;
2507
2508 if(scr<0)
2509 scr=cursor.screen;
2510
2511 mapscr *screen1;
2512
2513 if(prv_mode)
2514 {
2515 screen1=get_prvscr();
2516 }
2517 else
2518 {
2519 screen1=AbsoluteScr(cursor.map,cursor.screen);
2520 }
2521
2522 int32_t layermap;
2523 layermap=screen1->layermap[lyr]-1;
2524
2525 if(layermap<0 || layermap >= map_count) return 0;
2526
2527 mapscr *layer;
2528
2529 if(prv_mode)
2530 layer = &prvlayers[lyr];
2531 else
2532 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2533
2534 int32_t combo = COMBOPOS(x,y);
2535
2536 if(combo>175 || combo < 0)
2537 return 0;
2538
2539 return layer->sflag[combo];
2540 }
2541
2542 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2543 {
2544 if(map<0)
2545 map=cursor.map;
2546
2547 if(scr<0)
2548 scr=cursor.screen;
2549
2550 mapscr *screen1;
2551
2552 if(prv_mode)
2553 {
2554 screen1=get_prvscr();
2555 }
2556 else
2557 {
2558 screen1=AbsoluteScr(cursor.map,cursor.screen);
2559 }
2560
2561 x = vbound(x, 0, 16*16);
2562 y = vbound(y, 0, 11*16);
2563 int32_t combo = COMBOPOS(x,y);
2564
2565 if(combo>175 || combo < 0)
2566 return 0;
2567
2568 return screen1->sflag[combo];
2569 }
2570
2571 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2572 {
2573 mapscr *layers[7];
2574 mapscr *basescr;
2575 if(prv_mode)
2576 {
2577 layers[0] = &prvscr;
2578 basescr = layers[0];
2579 for(auto q = 1; q < 7; ++q)
2580 {
2581 if(prvlayers[q-1].valid)
2582 layers[q] = &(prvlayers[q-1]);
2583 else layers[q] = NULL;
2584 }
2585 }
2586 else
2587 {
2588 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2589 basescr = layers[0];
2590 for(auto q = 1; q < 7; ++q)
2591 {
2592 int32_t lmap = basescr->layermap[q-1]-1;
2593 int32_t lscr = basescr->layerscreen[q-1];
2594 if(lmap < 0)
2595 layers[q] = NULL;
2596 else layers[q] = AbsoluteScr(lmap, lscr);
2597 }
2598 }
2599 for(auto q = 0; q < 7; ++q)
2600 {
2601 if(!layers[q]) continue;
2602 for(auto pos = 0; pos < 176; ++pos)
2603 {
2604 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2605 if(cmb.type == cTORCH)
2606 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2607 }
2608 }
2609 word maxffc = basescr->numFFC();
2610 for(auto q = 0; q < maxffc; ++q)
2611 {
2612 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2613 if(cmb.type == cTORCH)
2614 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2615 }
2616 }
2617
2618 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2619 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2620 {
2621 newcombo const& cmb = combobuf[cid];
2622 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2623 if(dither)
2624 {
2625 if (LayerDitherSz == 0)
2626 return;
2627 BITMAP* buf = create_bitmap_ex(8,16,16);
2628 clear_bitmap(buf);
2629 overcombo(buf,0,0,cid,cset);
2630 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2631 if(over)
2632 {
2633 if(transp)
2634 {
2635 color_map = &trans_table2;
2636 draw_trans_sprite(dest, buf, x, y);
2637 color_map = &trans_table;
2638 }
2639 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2640 }
2641 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2642 destroy_bitmap(buf);
2643 }
2644 else if(over)
2645 {
2646 if(transp)
2647 overcombotranslucent(dest,x,y,cid,cset,0);
2648 else overcombo(dest,x,y,cid,cset);
2649 }
2650 else put_combo(dest,x,y,cid,cset,flags,sflag);
2651 }
2652 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2653 {
2654 if(!md) return;
2655 for (int32_t i = 0; i < 176; i++)
2656 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2657 }
2658 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2659 {
2660 if(!md) return;
2661 for (int32_t i = 0; i < 176; i++)
2662 {
2663 int data = md->data[i];
2664 if(combo_class_buf[combobuf[data].type].overhead)
2665 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2666 }
2667 }
2668 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2669 {
2670 if(!LayerMaskInt[lyr])
2671 return nullptr;
2672 if(lyr == 0)
2673 return basescr;
2674 int layermap = basescr->layermap[lyr-1]-1;
2675
2676 if(layermap>-1 && layermap<map_count)
2677 {
2678 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2679 return &TheMaps[layerscreen];
2680 }
2681 return nullptr;
2682 }
2683 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2684 {
2685 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2686 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2687
2688 if(map<0)
2689 map=cursor.map;
2690
2691 if(screen<0)
2692 screen=cursor.screen;
2693
2694 mapscr *basescr;
2695 mapscr* layers[7] = {nullptr};
2696
2697 if(prv_mode)
2698 {
2699 hl_layer = -1;
2700 basescr=get_prvscr();
2701 }
2702 else
2703 {
2704 basescr=AbsoluteScr(map,screen);
2705 }
2706 layers[0] = _zmap_get_lyr_checked(0,basescr);
2707 for(int lyr = 1; lyr < 7; ++lyr)
2708 {
2709 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2710 : _zmap_get_lyr_checked(lyr,basescr);
2711 }
2712
2713 int32_t layermap, layerscreen;
2714 if(CurrentLayer < 1)
2715 layermap = -1;
2716 else
2717 layermap=basescr->layermap[CurrentLayer-1]-1;
2718
2719 if(!(basescr->valid&mVALID))
2720 {
2721 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2722 rectfill(dest,x,y,x+255,y+175,vc(1));
2723
2724 if(ShowMisalignments)
2725 {
2726 check_alignments(dest,x,y,screen);
2727 }
2728
2729 return;
2730 }
2731
2732 if(LayerMaskInt[0]==0)
2733 {
2734 byte bgfill = 0;
2735 if (LayerDitherBG > -1)
2736 bgfill = vc(LayerDitherBG);
2737 rectfill(dest,x,y,x+255,y+175,bgfill);
2738 }
2739
2740 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2741 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2742
2743 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2744 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2745
2746 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2747
2748 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2749
2750 int num_ffcs = basescr->numFFC();
2751 for(int32_t i=num_ffcs-1; i>=0; i--)
2752 {
2753 if(basescr->ffcs[i].data)
2754 {
2755 if(!(basescr->ffcs[i].flags&ffc_changer))
2756 {
2757 if(!(basescr->ffcs[i].flags&ffc_overlay))
2758 {
2759 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2760 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2761
2762 if(basescr->ffcs[i].flags&ffc_trans)
2763 {
2764 overcomboblocktranslucent(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset,basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2765 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2766 }
2767 else
2768 {
2769 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2770 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2771 }
2772 }
2773 }
2774 }
2775 }
2776
2777 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2778 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2779
2780 int32_t doortype[4];
2781
2782 for(int32_t i=0; i<4; i++)
2783 {
2784 switch(basescr->door[i])
2785 {
2786 case dOPEN:
2787 doortype[i]=dt_pass;
2788 break;
2789
2790 case dLOCKED:
2791 doortype[i]=dt_lock;
2792 break;
2793
2794 case d1WAYSHUTTER:
2795 case dSHUTTER:
2796 doortype[i]=dt_shut;
2797 break;
2798
2799 case dBOSS:
2800 doortype[i]=dt_boss;
2801 break;
2802
2803 case dBOMB:
2804 doortype[i]=dt_bomb;
2805 break;
2806 }
2807 }
2808
2809 switch(basescr->door[up])
2810 {
2811 case dBOMB:
2812 over_door(dest,39,up,x,y,false, screen);
2813 [[fallthrough]];
2814 case dOPEN:
2815 case dLOCKED:
2816 case d1WAYSHUTTER:
2817 case dSHUTTER:
2818 case dBOSS:
2819 put_door(dest,7,up,doortype[up],x,y,false,screen);
2820 break;
2821
2822 case dWALK:
2823 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2824 {
2825 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2826 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2827 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0]);
2828 }
2829 else
2830
2831 {
2832 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2833 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2834 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0],0,0);
2835 }
2836
2837 break;
2838 }
2839
2840 switch(basescr->door[down])
2841 {
2842 case dBOMB:
2843 over_door(dest,135,down,x,y,false,screen);
2844 [[fallthrough]];
2845 case dOPEN:
2846 case dLOCKED:
2847 case d1WAYSHUTTER:
2848 case dSHUTTER:
2849 case dBOSS:
2850 put_door(dest,151,down,doortype[down],x,y,false,screen);
2851 break;
2852
2853 case dWALK:
2854 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2855 {
2856 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2857 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2858 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1]);
2859 }
2860 else
2861 {
2862 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2863 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2864 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1],0,0);
2865 }
2866
2867 break;
2868 }
2869
2870 switch(basescr->door[left])
2871 {
2872 case dBOMB:
2873 over_door(dest,66,left,x,y,false,screen);
2874 [[fallthrough]];
2875 case dOPEN:
2876 case dLOCKED:
2877 case d1WAYSHUTTER:
2878 case dSHUTTER:
2879 case dBOSS:
2880 put_door(dest,64,left,doortype[left],x,y,false,screen);
2881 break;
2882
2883 case dWALK:
2884 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2885 {
2886 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2887 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2888 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2]);
2889 }
2890 else
2891 {
2892 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2893 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2894 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2],0,0);
2895 }
2896
2897 break;
2898 }
2899
2900 switch(basescr->door[right])
2901 {
2902
2903 case dBOMB:
2904 over_door(dest,77,right,x,y,false,screen);
2905 [[fallthrough]];
2906 case dOPEN:
2907 case dLOCKED:
2908 case d1WAYSHUTTER:
2909 case dSHUTTER:
2910 case dBOSS:
2911 put_door(dest,78,right,doortype[right],x,y,false,screen);
2912 break;
2913
2914 case dWALK:
2915 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2916 {
2917 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2918 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2919 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3]);
2920 }
2921 else
2922 {
2923 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2924 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2925 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3],0,0);
2926 }
2927
2928 break;
2929 }
2930
2931 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2932 {
2933 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2934 }
2935
2936 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2937 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2938 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2939
2940 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2941
2942 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2943 {
2944 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2945 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2946 }
2947 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2948
2949 for(int32_t i=num_ffcs-1; i>=0; i--)
2950 {
2951 if(basescr->ffcs[i].data)
2952 {
2953 if(!(basescr->ffcs[i].flags&ffc_changer))
2954 {
2955 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2956 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2957
2958 if(basescr->ffcs[i].flags&ffc_overlay)
2959 {
2960 if(basescr->ffcs[i].flags&ffc_trans)
2961 {
2962 //overtiletranslucent16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip, 128);
2963 overcomboblocktranslucent(dest,tx,ty,basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i),128);
2964 }
2965 else
2966 {
2967 //overtile16(dest, combo_tile(basescr->ffcs[i].data,tx,ty)+(j*20)+(l), tx, ty, basescr->ffcs[i].cset, combobuf[basescr->ffcs[i].data].flip);
2968 overcomboblock(dest, tx, ty, basescr->ffcs[i].data, basescr->ffcs[i].cset, basescr->ffTileWidth(i), basescr->ffTileHeight(i));
2969 }
2970 }
2971 }
2972 }
2973 }
2974
2975 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2976
2977 for(int32_t i=num_ffcs-1; i>=0; i--)
2978 if(basescr->ffcs[i].data)
2979 if(basescr->ffcs[i].flags&ffc_changer)
2980 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2981
2982 if(flags&cWALK)
2983 {
2984 if(layers[0])
2985 for(int32_t i=0; i<176; i++)
2986 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2987
2988 for(int32_t k=0; k<2; k++)
2989 {
2990 if(layers[k+1])
2991 for(int32_t i=0; i<176; i++)
2992 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2993 }
2994 for(int32_t i=num_ffcs-1; i>=0; i--)
2995 {
2996 if(auto data = basescr->ffcs[i].data)
2997 {
2998 if(!(basescr->ffcs[i].flags&ffc_changer))
2999 {
3000 newcombo const& cmb = combobuf[data];
3001 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
3002 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
3003
3004 if(basescr->ffcs[i].flags&ffc_solid)
3005 {
3006 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
3007 }
3008
3009 if(cmb.type == cSLOPE)
3010 {
3011 slope_info s(cmb, tx, ty);
3012 s.draw(dest, 0, 0, COLOR_SLOPE);
3013 }
3014 }
3015 }
3016 }
3017 }
3018
3019 if(flags&cFLAGS)
3020 {
3021 if(LayerMaskInt[CurrentLayer]!=0)
3022 {
3023 for(int32_t i=0; i<176; i++)
3024 {
3025 if(CurrentLayer==0)
3026 {
3027 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
3028 }
3029 else
3030 {
3031 if(prv_mode)
3032 {
3033 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
3034 }
3035 else if(basescr->layermap[CurrentLayer-1] > 0)
3036 {
3037 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
3038
3039 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3040 {
3041 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
3042 TheMaps[_lscr].data[i],
3043 TheMaps[_lscr].cset[i], flags,
3044 TheMaps[_lscr].sflag[i]);
3045 }
3046 }
3047 }
3048 }
3049 }
3050 }
3051
3052 int32_t dark = basescr->flags&cDARK;
3053
3054 if(dark && !(flags&cNODARK)
3055 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
3056 {
3057 for(int32_t j=0; j<80; j++)
3058 {
3059 for(int32_t i=0; i<(80)-j; i++)
3060 {
3061 if(((i^j)&1)==0)
3062 {
3063 putpixel(dest,x+i,y+j,vc(blackout_color));
3064 }
3065 }
3066 }
3067 }
3068
3069 if(ShowMisalignments)
3070 {
3071 check_alignments(dest,x,y,screen);
3072 }
3073 }
3074
3075 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3076 {
3077 if(map<0)
3078 map=cursor.map;
3079
3080 if(scr<0)
3081 scr=cursor.screen;
3082
3083 mapscr* layer=AbsoluteScr(map,scr);
3084 int32_t layermap=0, layerscreen=0;
3085
3086 if(!(layer->valid&mVALID))
3087 {
3088 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3089 rectfill(dest,x,y,x+255,y+15,vc(1));
3090 return;
3091 }
3092
3093 int32_t dark = layer->flags&4;
3094
3095 if(LayerMaskInt[0]==0)
3096 {
3097 rectfill(dest,x,y,x+255,y+15,0);
3098 }
3099
3100
3101 for(int32_t k=1; k<3; k++)
3102 {
3103 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3104 {
3105 layermap=layer->layermap[k]-1;
3106
3107 if(layermap>-1 && layermap<map_count)
3108 {
3109 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3110
3111 for(int32_t i=c; i<(c&0xF0)+16; i++)
3112 {
3113 auto data = TheMaps[layerscreen].data[i];
3114 auto cs = TheMaps[layerscreen].cset[i];
3115 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3116 }
3117 }
3118 }
3119 }
3120
3121 if(LayerMaskInt[0]!=0)
3122 {
3123 for(int32_t i=c; i<(c&0xF0)+16; i++)
3124 {
3125 word cmbdat = (i < 176 ? layer->data[i] : 0);
3126 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3127 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3128 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3129 cmbflag,(layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3130 }
3131 }
3132
3133 for(int32_t k=0; k<2; k++)
3134 {
3135 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3136 {
3137 layermap=layer->layermap[k]-1;
3138
3139 if(layermap>-1 && layermap<map_count)
3140 {
3141 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3142
3143 for(int32_t i=c; i<(c&0xF0)+16; i++)
3144 {
3145 auto data = TheMaps[layerscreen].data[i];
3146 auto cs = TheMaps[layerscreen].cset[i];
3147 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3148 }
3149 }
3150 }
3151 }
3152
3153 int32_t doortype[4];
3154
3155 for(int32_t i=0; i<4; i++)
3156 {
3157 switch(layer->door[i])
3158 {
3159 case dOPEN:
3160 doortype[i]=dt_pass;
3161 break;
3162
3163 case dLOCKED:
3164 doortype[i]=dt_lock;
3165 break;
3166
3167 case d1WAYSHUTTER:
3168 case dSHUTTER:
3169 doortype[i]=dt_shut;
3170 break;
3171
3172 case dBOSS:
3173 doortype[i]=dt_boss;
3174 break;
3175
3176 case dBOMB:
3177 doortype[i]=dt_bomb;
3178 break;
3179 }
3180 }
3181
3182 if(c<16)
3183 {
3184 switch(layer->door[up])
3185 {
3186 case dBOMB:
3187 case dOPEN:
3188 case dLOCKED:
3189 case d1WAYSHUTTER:
3190 case dSHUTTER:
3191 case dBOSS:
3192 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3193 break;
3194 }
3195 }
3196 else if(c>159)
3197 {
3198 switch(layer->door[down])
3199 {
3200 case dBOMB:
3201 case dOPEN:
3202 case dLOCKED:
3203 case d1WAYSHUTTER:
3204 case dSHUTTER:
3205 case dBOSS:
3206 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3207 break;
3208 }
3209 }
3210
3211 for(int32_t k=2; k<4; k++)
3212 {
3213 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3214 {
3215 layermap=layer->layermap[k]-1;
3216
3217 if(layermap>-1 && layermap<map_count)
3218 {
3219 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3220
3221 for(int32_t i=c; i<(c&0xF0)+16; i++)
3222 {
3223 if(layer->layeropacity[k]<255)
3224 {
3225 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3226 }
3227 else
3228 {
3229 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3230 }
3231 }
3232 }
3233 }
3234 }
3235
3236 //Overhead L0
3237 if(LayerMaskInt[0]!=0)
3238 {
3239 for(int32_t i=c; i<(c&0xF0)+16; i++)
3240 {
3241 int32_t ct1=layer->data[i];
3242 int32_t ct3=combobuf[ct1].type;
3243
3244 if(combo_class_buf[ct3].overhead)
3245 {
3246 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3247 }
3248 }
3249 }
3250
3251 //Overhead L1/2
3252 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3253 {
3254 for(int32_t k = 0; k < 2; ++k)
3255 {
3256 if(LayerMaskInt[k+1]!=0)
3257 {
3258 layermap=layer->layermap[k]-1;
3259
3260 if(layermap>-1 && layermap<map_count)
3261 {
3262 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3263 for(int32_t i=c; i<(c&0xF0)+16; i++)
3264 {
3265 auto data = TheMaps[layerscreen].data[i];
3266 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3267 auto cs = TheMaps[layerscreen].cset[i];
3268 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3269 }
3270 }
3271 }
3272 }
3273 }
3274
3275 for(int32_t k=4; k<6; k++)
3276 {
3277 if(LayerMaskInt[k+1]!=0)
3278 {
3279 layermap=layer->layermap[k]-1;
3280
3281 if(layermap>-1 && layermap<map_count)
3282 {
3283 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3284
3285 for(int32_t i=c; i<(c&0xF0)+16; i++)
3286 {
3287 auto data = TheMaps[layerscreen].data[i];
3288 auto cs = TheMaps[layerscreen].cset[i];
3289 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3290 }
3291 }
3292 }
3293 }
3294
3295 if(flags&cWALK)
3296 {
3297 if(LayerMaskInt[0]!=0)
3298 {
3299 for(int32_t i=c; i<(c&0xF0)+16; i++)
3300 {
3301 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3302 }
3303 }
3304
3305 for(int32_t k=0; k<2; k++)
3306 {
3307 if(LayerMaskInt[k+1]!=0)
3308 {
3309 for(int32_t i=c; i<(c&0xF0)+16; i++)
3310 {
3311 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3312 }
3313 }
3314 }
3315 }
3316
3317 if(flags&cFLAGS)
3318 {
3319 if(LayerMaskInt[CurrentLayer]!=0)
3320 {
3321 for(int32_t i=c; i<(c&0xF0)+16; i++)
3322 {
3323 if(CurrentLayer==0)
3324 {
3325 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3326 }
3327 else
3328 {
3329 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3330
3331 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3332 {
3333 if(i < 176)
3334 {
3335 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3336 TheMaps[_lscr].data[i],
3337 TheMaps[_lscr].cset[i], flags|dark,
3338 TheMaps[_lscr].sflag[i]);
3339 }
3340 else
3341 {
3342 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3343 }
3344 }
3345 }
3346 }
3347 }
3348
3349 /*
3350 if (LayerMaskInt[0]!=0) {
3351 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3352 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3353 }
3354 }
3355 */
3356 }
3357
3358 if(ShowMisalignments)
3359 {
3360 if(c<16)
3361 {
3362 check_alignments(dest,x,y,scr);
3363 }
3364 else if(c>159)
3365 {
3366 check_alignments(dest,x,y-160,scr);
3367 }
3368 }
3369 }
3370
3371 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3372 {
3373 if(map<0)
3374 map=cursor.map;
3375
3376 if(scr<0)
3377 scr=cursor.screen;
3378
3379 mapscr* layer=AbsoluteScr(map,scr);
3380 int32_t layermap=0, layerscreen=0;
3381
3382 if(!(layer->valid&mVALID))
3383 {
3384 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3385 rectfill(dest,x,y,x+15,y+175,vc(1));
3386 return;
3387 }
3388
3389 int32_t dark = layer->flags&4;
3390
3391 if(LayerMaskInt[0]==0)
3392 {
3393 rectfill(dest,x,y,x+15,y+175,0);
3394 }
3395
3396
3397 for(int32_t k=1; k<3; k++)
3398 {
3399 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3400 {
3401 layermap=layer->layermap[k]-1;
3402
3403 if(layermap>-1 && layermap<map_count)
3404 {
3405 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3406
3407 for(int32_t i=c; i<176; i+=16)
3408 {
3409 auto data = TheMaps[layerscreen].data[i];
3410 auto cs = TheMaps[layerscreen].cset[i];
3411 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3412 }
3413 }
3414 }
3415 }
3416
3417 if(LayerMaskInt[0]!=0)
3418 {
3419 for(int32_t i=c; i<176; i+=16)
3420 {
3421 word cmbdat = layer->data[i];
3422 byte cmbcset = layer->cset[i];
3423 int32_t cmbflag = layer->sflag[i];
3424 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3425 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3426 }
3427 }
3428
3429 for(int32_t k=0; k<2; k++)
3430 {
3431 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3432 {
3433 layermap=layer->layermap[k]-1;
3434
3435 if(layermap>-1 && layermap<map_count)
3436 {
3437 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3438
3439 for(int32_t i=c; i<176; i+=16)
3440 {
3441 auto data = TheMaps[layerscreen].data[i];
3442 auto cs = TheMaps[layerscreen].cset[i];
3443 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3444 }
3445 }
3446 }
3447 }
3448
3449 int32_t doortype[4];
3450
3451 for(int32_t i=0; i<4; i++)
3452 {
3453 switch(layer->door[i])
3454 {
3455 case dOPEN:
3456 doortype[i]=dt_pass;
3457 break;
3458
3459 case dLOCKED:
3460 doortype[i]=dt_lock;
3461 break;
3462
3463 case d1WAYSHUTTER:
3464 case dSHUTTER:
3465 doortype[i]=dt_shut;
3466 break;
3467
3468 case dBOSS:
3469 doortype[i]=dt_boss;
3470 break;
3471
3472 case dBOMB:
3473 doortype[i]=dt_bomb;
3474 break;
3475 }
3476 }
3477
3478 if((c&0x0F)==0)
3479 {
3480 switch(layer->door[left])
3481 {
3482
3483 case dBOMB:
3484 case dOPEN:
3485 case dLOCKED:
3486 case d1WAYSHUTTER:
3487 case dSHUTTER:
3488 case dBOSS:
3489 // put_door(dest,64,left,doortype[left],x+256,y,true);
3490 put_door(dest,64,left,doortype[left],x,y,true,scr);
3491 break;
3492 }
3493 }
3494 else if((c&0x0F)==15)
3495 {
3496 switch(layer->door[right])
3497 {
3498 case dBOMB:
3499 case dOPEN:
3500 case dLOCKED:
3501 case d1WAYSHUTTER:
3502 case dSHUTTER:
3503 case dBOSS:
3504 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3505 break;
3506 }
3507 }
3508
3509 for(int32_t k=2; k<4; k++)
3510 {
3511 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3512 {
3513 layermap=layer->layermap[k]-1;
3514
3515 if(layermap>-1 && layermap<map_count)
3516 {
3517 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3518
3519 for(int32_t i=c; i<176; i+=16)
3520 {
3521 auto data = TheMaps[layerscreen].data[i];
3522 auto cs = TheMaps[layerscreen].cset[i];
3523 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3524 }
3525 }
3526 }
3527 }
3528
3529 //Overhead L0
3530 if(LayerMaskInt[0]!=0)
3531 {
3532 for(int32_t i=c; i<176; i+=16)
3533 {
3534 auto data = TheMaps[layerscreen].data[i];
3535 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3536 auto cs = TheMaps[layerscreen].cset[i];
3537 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3538 }
3539 }
3540 //Overhead L1/2
3541 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3542 {
3543 for(int32_t k = 0; k < 2; ++k)
3544 {
3545 if(LayerMaskInt[k+1]!=0)
3546 {
3547 layermap=layer->layermap[k]-1;
3548
3549 if(layermap>-1 && layermap<map_count)
3550 {
3551 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3552 for(int32_t i=c; i<176; i+=16)
3553 {
3554 auto data = TheMaps[layerscreen].data[i];
3555 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3556 auto cs = TheMaps[layerscreen].cset[i];
3557 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3558 }
3559 }
3560 }
3561 }
3562 }
3563
3564
3565 for(int32_t k=4; k<6; k++)
3566 {
3567 if(LayerMaskInt[k+1]!=0)
3568 {
3569 layermap=layer->layermap[k]-1;
3570
3571 if(layermap>-1 && layermap<map_count)
3572 {
3573 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3574
3575 for(int32_t i=c; i<176; i+=16)
3576 {
3577 auto data = TheMaps[layerscreen].data[i];
3578 auto cs = TheMaps[layerscreen].cset[i];
3579 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3580 }
3581 }
3582 }
3583 }
3584
3585 if(flags&cWALK)
3586 {
3587 if(LayerMaskInt[0]!=0)
3588 {
3589 for(int32_t i=c&0xF; i<176; i+=16)
3590 {
3591 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3592 }
3593 }
3594
3595 for(int32_t k=0; k<2; k++)
3596 {
3597 if(LayerMaskInt[k+1]!=0)
3598 {
3599 for(int32_t i=c&0xF; i<176; i+=16)
3600 {
3601 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3602 }
3603 }
3604 }
3605 }
3606
3607 if(flags&cFLAGS)
3608 {
3609 if(LayerMaskInt[CurrentLayer]!=0)
3610 {
3611 for(int32_t i=c; i<176; i+=16)
3612 {
3613 if(CurrentLayer==0)
3614 {
3615 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3616 }
3617 else
3618 {
3619 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3620
3621 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3622 {
3623 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3624 TheMaps[_lscr].data[i],
3625 TheMaps[_lscr].cset[i], flags|dark,
3626 TheMaps[_lscr].sflag[i]);
3627 }
3628 }
3629 }
3630 }
3631 }
3632
3633 if(ShowMisalignments)
3634 {
3635 if((c&0x0F)==0)
3636 {
3637 check_alignments(dest,x,y,scr);
3638 }
3639 else if((c&0x0F)==15)
3640 {
3641 check_alignments(dest,x-240,y,scr);
3642 }
3643 }
3644 }
3645
3646 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3647 {
3648 if(map<0)
3649 map=cursor.map;
3650
3651 if(scr<0)
3652 scr=cursor.screen;
3653
3654 mapscr* layer=AbsoluteScr(map,scr);
3655 int32_t layermap=0, layerscreen=0;
3656
3657 if(!(layer->valid&mVALID))
3658 {
3659 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3660 rectfill(dest,x,y,x+15,y+15,vc(1));
3661 return;
3662 }
3663
3664 int32_t dark = layer->flags&4;
3665
3666 if(LayerMaskInt[0]!=0)
3667 {
3668 rectfill(dest,x,y,x+15,y+15,0);
3669 }
3670
3671 for(int32_t k=1; k<3; k++)
3672 {
3673 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3674 {
3675 layermap=layer->layermap[k]-1;
3676
3677 if(layermap>-1 && layermap<map_count)
3678 {
3679 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3680
3681 auto data = TheMaps[layerscreen].data[c];
3682 auto cs = TheMaps[layerscreen].cset[c];
3683 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3684 }
3685 }
3686 }
3687
3688 if(LayerMaskInt[0]!=0)
3689 {
3690 word cmbdat = layer->data[c];
3691 byte cmbcset = layer->cset[c];
3692 int32_t cmbflag = layer->sflag[c];
3693 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3694 (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3695 }
3696
3697
3698 for(int32_t k=0; k<2; k++)
3699 {
3700 if(LayerMaskInt[k+1]!=0)
3701 {
3702 layermap=layer->layermap[k]-1;
3703
3704 if(layermap>-1 && layermap<map_count)
3705 {
3706 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3707
3708 auto data = TheMaps[layerscreen].data[c];
3709 auto cs = TheMaps[layerscreen].cset[c];
3710 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3711 }
3712 }
3713 }
3714
3715 for(int32_t k=2; k<4; k++)
3716 {
3717 if(LayerMaskInt[k+1]!=0)
3718 {
3719 layermap=layer->layermap[k]-1;
3720
3721 if(layermap>-1 && layermap<map_count)
3722 {
3723 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3724 auto data = TheMaps[layerscreen].data[c];
3725 auto cs = TheMaps[layerscreen].cset[c];
3726 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3727 }
3728 }
3729 }
3730
3731 //Overhead L0
3732 if(LayerMaskInt[0]!=0)
3733 {
3734 auto data = TheMaps[layerscreen].data[c];
3735 if(combo_class_buf[combobuf[data].type].overhead)
3736 {
3737 auto cs = TheMaps[layerscreen].cset[c];
3738 drawcombo(dest,x,y,data,cs,0,0);
3739 }
3740 }
3741 //Overhead L1/2
3742 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3743 {
3744 for(int32_t k = 0; k < 2; ++k)
3745 {
3746 if(LayerMaskInt[k+1]!=0)
3747 {
3748 layermap=layer->layermap[k]-1;
3749
3750 if(layermap>-1 && layermap<map_count)
3751 {
3752 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3753 auto data = TheMaps[layerscreen].data[c];
3754 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3755 auto cs = TheMaps[layerscreen].cset[c];
3756 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3757 }
3758 }
3759 }
3760 }
3761
3762
3763 for(int32_t k=4; k<6; k++)
3764 {
3765 if(LayerMaskInt[k+1]!=0)
3766 {
3767 layermap=layer->layermap[k]-1;
3768
3769 if(layermap>-1 && layermap<map_count)
3770 {
3771 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3772 auto data = TheMaps[layerscreen].data[c];
3773 auto cs = TheMaps[layerscreen].cset[c];
3774 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3775 }
3776 }
3777 }
3778
3779 if(flags&cWALK)
3780 {
3781 if(LayerMaskInt[0]!=0)
3782 {
3783 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3784 }
3785
3786 for(int32_t k=0; k<2; k++)
3787 {
3788 if(LayerMaskInt[k+1]!=0)
3789 {
3790 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3791 }
3792 }
3793 }
3794
3795 if(flags&cFLAGS)
3796 {
3797 if(LayerMaskInt[CurrentLayer]!=0)
3798 {
3799 int32_t i = c;
3800 //for(int32_t i=c; i==c; i++)
3801 {
3802 if(CurrentLayer==0)
3803 {
3804 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3805 }
3806 else
3807 {
3808 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3809
3810 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3811 {
3812 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3813 TheMaps[_lscr].data[i],
3814 TheMaps[_lscr].cset[i], flags|dark,
3815 TheMaps[_lscr].sflag[i]);
3816 }
3817 }
3818 }
3819 }
3820 }
3821
3822 if(ShowMisalignments)
3823 {
3824 switch(c)
3825 {
3826 case 0:
3827 check_alignments(dest,x,y,scr);
3828 break;
3829
3830 case 15:
3831 check_alignments(dest,x-240,y,scr);
3832 break;
3833
3834 case 160:
3835 check_alignments(dest,x,y-160,scr);
3836 break;
3837
3838 case 175:
3839 check_alignments(dest,x-240,y-160,scr);
3840 break;
3841 }
3842 }
3843 }
3844
3845 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3846 {
3847 if (InvalidBG == 2)
3848 {
3849 draw_checkerboard(dest, x, y, 16);
3850 }
3851 else if(InvalidBG == 1)
3852 {
3853 for(int32_t dy=0; dy<16; dy++)
3854 {
3855 for(int32_t dx=0; dx<16; dx++)
3856 {
3857 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3858 }
3859 }
3860 }
3861 else
3862 {
3863 rectfill(dest, x, y, x+15, y+15, vc(0));
3864 rect(dest, x, y, x+15, y+15, vc(15));
3865 line(dest, x, y, x+15, y+15, vc(15));
3866 line(dest, x, y+15, x+15, y, vc(15));
3867 }
3868 }
3869
3870 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3871 {
3872 if (InvalidBG == 2)
3873 {
3874 for(int32_t q = 0; q < 11; ++q)
3875 draw_checkerboard(dest, x, y + q * 16, 16);
3876 }
3877 else if(InvalidBG == 1)
3878 {
3879 for(int32_t dy=0; dy<176; dy++)
3880 {
3881 for(int32_t dx=0; dx<16; dx++)
3882 {
3883 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3884 }
3885 }
3886 }
3887 else
3888 {
3889 rectfill(dest, x, y, x+15, y+175, vc(0));
3890 rect(dest, x, y, x+15, y+175, vc(15));
3891 line(dest, x, y, x+15, y+175, vc(15));
3892 line(dest, x, y+175, x+15, y, vc(15));
3893 }
3894 }
3895
3896 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3897 {
3898 if (InvalidBG == 2)
3899 {
3900 for (int32_t q = 0; q < 16; ++q)
3901 draw_checkerboard(dest, x + q * 16, y, 16);
3902 }
3903 else if(InvalidBG == 1)
3904 {
3905 for(int32_t dy=0; dy<16; dy++)
3906 {
3907 for(int32_t dx=0; dx<256; dx++)
3908 {
3909 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3910 }
3911 }
3912 }
3913 else
3914 {
3915 rectfill(dest, x, y, x+255, y+15, vc(0));
3916 rect(dest, x, y, x+255, y+15, vc(15));
3917 line(dest, x, y, x+255, y+15, vc(15));
3918 line(dest, x, y+15, x+255, y, vc(15));
3919 }
3920 }
3921
3922 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3923 {
3924 for(int32_t i=0; i<176; i++)
3925 {
3926 word cmbdat = screens[TEMPLATE].data[i];
3927 byte cmbcset = screens[TEMPLATE].cset[i];
3928 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3929 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3930 }
3931 }
3932
3933 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3934 {
3935 for(int32_t i=0; i<176; i++)
3936 {
3937 word cmbdat = screens[TEMPLATE2].data[i];
3938 byte cmbcset = screens[TEMPLATE2].cset[i];
3939 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3940 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3941 }
3942 }
3943
3944 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3945 {
3946 word cmbdat = screens[TEMPLATE].data[pos];
3947 byte cmbcset = screens[TEMPLATE].cset[pos];
3948 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3949 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3950 }
3951
3952 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3953 {
3954 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3955 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3956 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3957 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3958 }
3959
3960 void zmap::scroll(int32_t dir, bool warp)
3961 {
3962 if(cursor.map<map_count)
3963 {
3964 switch(dir)
3965 {
3966 case up:
3967 if(warp && Map.CurrScr()->flags2&wfUP)
3968 {
3969 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3970 }
3971 else if(cursor.screen>15)
3972 {
3973 setCurrScr(cursor.screen - 16);
3974 }
3975
3976 break;
3977
3978 case down:
3979 if(warp && Map.CurrScr()->flags2&wfDOWN)
3980 {
3981 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3982 }
3983 else if(cursor.screen<MAPSCRS-16)
3984 {
3985 setCurrScr(cursor.screen + 16);
3986 }
3987
3988 break;
3989
3990 case left:
3991 if(warp && Map.CurrScr()->flags2&wfLEFT)
3992 {
3993 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3994 }
3995 else if(cursor.screen&15)
3996 {
3997 setCurrScr(cursor.screen - 1);
3998 }
3999
4000 break;
4001
4002 case right:
4003 if(warp && Map.CurrScr()->flags2&wfRIGHT)
4004 {
4005 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
4006 }
4007 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
4008 {
4009 setCurrScr(cursor.screen + 1);
4010 }
4011
4012 break;
4013 }
4014 }
4015 }
4016
4017 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
4018 {
4019 switch(side)
4020 {
4021 case up:
4022 switch(door)
4023 {
4024 case dWALL:
4025 case dBOMB:
4026 case dWALK:
4027 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
4028 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
4029 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
4030 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
4031 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
4032 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
4033 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
4034 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
4035 break;
4036
4037 default:
4038 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
4039 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
4040 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
4041 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4042 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4043 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4044 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4045 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4046 break;
4047 }
4048
4049 break;
4050
4051 case down:
4052 switch(door)
4053 {
4054 case dWALL:
4055 case dBOMB:
4056 case dWALK:
4057 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4058 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4059 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4060 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4061 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4062 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4063 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4064 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4065 break;
4066
4067 default:
4068 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4069 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4070 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4071 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4072 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4073 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4074 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4075 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4076 break;
4077 }
4078
4079 break;
4080
4081 case left:
4082 switch(door)
4083 {
4084 case dWALL:
4085 case dBOMB:
4086 case dWALK:
4087 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4088 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4089 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4090 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4091 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4092 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4093 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4094 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4095 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4096 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4097 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4098 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4099 break;
4100
4101 default:
4102 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4103 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4104 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4105 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4106 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4107 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4108 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4109 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4110 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4111 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4112 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4113 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4114 break;
4115 }
4116
4117 break;
4118
4119 case right:
4120 switch(door)
4121 {
4122 case dWALL:
4123 case dBOMB:
4124 case dWALK:
4125 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4126 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4127 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4128 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4129 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4130 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4131 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4132 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4133 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4134 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4135 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4136 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4137 break;
4138
4139 default:
4140 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4141 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4142 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4143 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4144 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4145 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4146 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4147 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4148 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4149 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4150 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4151 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4152 break;
4153 }
4154
4155 break;
4156 }
4157 }
4158 void zmap::DoPutDoorCommand(int side, int door, bool force)
4159 {
4160 if(!force && screens[cursor.screen].door[side] == door)
4161 return;
4162 bool already_list = InListCommand();
4163 if(!already_list)
4164 StartListCommand();
4165 DoSetDoorCommand(cursor.screen,side,door);
4166 if(door != dNONE)
4167 {
4168 word data[176] = {0};
4169 byte cset[176] = {0};
4170 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4171 for(int q = 0; q < 176; ++q)
4172 if(data[q])
4173 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4174 }
4175 if(!already_list)
4176 FinishListCommand();
4177 }
4178 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4179 {
4180 if(screens[screen].door[side] == door)
4181 return;
4182
4183 screens[screen].door[side] = door;
4184 if(door != dNONE)
4185 {
4186 word data[176] = {0};
4187 byte cset[176] = {0};
4188 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4189 for(int q = 0; q < 176; ++q)
4190 if(data[q])
4191 {
4192 screens[screen].data[q] = data[q];
4193 screens[screen].cset[q] = cset[q];
4194 }
4195 }
4196 }
4197
4198 void list_command::execute()
4199 {
4200 for (auto command : commands)
4201 {
4202 command->execute();
4203 }
4204 }
4205
4206 void list_command::undo()
4207 {
4208 for (int i = commands.size() - 1; i >= 0; i--)
4209 {
4210 commands[i]->undo();
4211 }
4212 }
4213
4214 int list_command::size()
4215 {
4216 int s = 0;
4217 for (auto command : commands)
4218 {
4219 s += command->size();
4220 }
4221 return s;
4222 }
4223
4224 void set_combo_command::execute()
4225 {
4226 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4227 if (!scr_ptr) return;
4228
4229 if (combo != -1) scr_ptr->data[pos] = combo;
4230 scr_ptr->cset[pos] = cset;
4231 }
4232
4233 void set_combo_command::undo()
4234 {
4235 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4236 if(!mapscr_ptr) return;
4237 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4238 mapscr_ptr->cset[pos] = prev_cset;
4239 }
4240
4241 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4242 {
4243 std::array<int, 8> initd_arr;
4244 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4245
4246 return {
4247 .x = ffc.x,
4248 .y = ffc.y,
4249 .vx = ffc.vx,
4250 .vy = ffc.vy,
4251 .ax = ffc.ax,
4252 .ay = ffc.ay,
4253 .data = ffc.data,
4254 .cset = ffc.cset,
4255 .delay = ffc.delay,
4256 .link = ffc.link,
4257 .script = ffc.script,
4258 .tw = ffc.txsz,
4259 .th = ffc.tysz,
4260 .ew = ffc.hit_width,
4261 .eh = ffc.hit_height,
4262 .flags = ffc.flags,
4263 .initd = initd_arr,
4264 .layer = ffc.layer
4265 };
4266 }
4267
4268 void set_ffc_command::execute()
4269 {
4270 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4271 if(!mapscr_ptr) return;
4272
4273 mapscr_ptr->valid |= mVALID;
4274 mapscr_ptr->ffcs[i].x = data.x;
4275 mapscr_ptr->ffcs[i].y = data.y;
4276 mapscr_ptr->ffcs[i].vx = data.vx;
4277 mapscr_ptr->ffcs[i].vy = data.vy;
4278 mapscr_ptr->ffcs[i].ax = data.ax;
4279 mapscr_ptr->ffcs[i].ay = data.ay;
4280 mapscr_ptr->ffcs[i].data = data.data;
4281 mapscr_ptr->ffcs[i].cset = data.cset;
4282 mapscr_ptr->ffcs[i].delay = data.delay;
4283 mapscr_ptr->ffcs[i].link = data.link;
4284 mapscr_ptr->ffcs[i].script = data.script;
4285 mapscr_ptr->ffcs[i].flags = data.flags;
4286 mapscr_ptr->ffEffectWidth(i, data.ew);
4287 mapscr_ptr->ffEffectHeight(i, data.eh);
4288 mapscr_ptr->ffTileWidth(i, data.tw);
4289 mapscr_ptr->ffTileHeight(i, data.th);
4290 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4291 mapscr_ptr->ffcs[i].layer = data.layer;
4292 mapscr_ptr->ffcCountMarkDirty();
4293 mapscr_ptr->ffcs[i].updateSolid();
4294 }
4295
4296 void set_ffc_command::undo()
4297 {
4298 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4299 if(!mapscr_ptr) return;
4300
4301 mapscr_ptr->ffcs[i].x = prev_data.x;
4302 mapscr_ptr->ffcs[i].y = prev_data.y;
4303 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4304 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4305 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4306 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4307 mapscr_ptr->ffcs[i].data = prev_data.data;
4308 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4309 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4310 mapscr_ptr->ffcs[i].link = prev_data.link;
4311 mapscr_ptr->ffcs[i].script = prev_data.script;
4312 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4313 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4314 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4315 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4316 mapscr_ptr->ffTileHeight(i, prev_data.th);
4317 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4318 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4319 mapscr_ptr->ffcCountMarkDirty();
4320 mapscr_ptr->ffcs[i].updateSolid();
4321 }
4322
4323 void set_flag_command::execute()
4324 {
4325 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4326 if(!mapscr_ptr) return;
4327
4328 mapscr_ptr->valid |= mVALID;
4329 mapscr_ptr->sflag[pos] = flag;
4330 }
4331
4332 void set_flag_command::undo()
4333 {
4334 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4335 if(!mapscr_ptr) return;
4336 mapscr_ptr->sflag[pos] = prev_flag;
4337 }
4338
4339 void set_door_command::execute()
4340 {
4341 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4342 if(!mapscr_ptr) return;
4343
4344 mapscr_ptr->valid |= mVALID;
4345 mapscr_ptr->door[side] = door;
4346 }
4347
4348 void set_door_command::undo()
4349 {
4350 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4351 }
4352
4353 void set_dcs_command::execute()
4354 {
4355 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4356 if(!mapscr_ptr) return;
4357
4358 mapscr_ptr->valid |= mVALID;
4359 mapscr_ptr->door_combo_set = dcs;
4360 }
4361
4362 void set_dcs_command::undo()
4363 {
4364 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4365 }
4366
4367 void paste_screen_command::execute()
4368 {
4369 perform(screen.get());
4370 }
4371
4372 void paste_screen_command::undo()
4373 {
4374 if (prev_screens.size() > 1)
4375 {
4376 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4377 ASSERT(prev_screens.size() == 128);
4378 for (int i = 0; i < 128; i++)
4379 {
4380 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4381 // TODO: why not just this?
4382 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4383 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4384 }
4385 return;
4386 }
4387
4388 perform(prev_screens[0].get());
4389 }
4390
4391 int paste_screen_command::size()
4392 {
4393 return prev_screens.size() + 1;
4394 }
4395
4396 void paste_screen_command::perform(mapscr* to)
4397 {
4398 if (to)
4399 {
4400 switch (type) {
4401 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4402 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4403 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4404 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4405 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4406 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4407 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4408 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4409 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4410 case ScreenPartial: Map.Paste(*to, screen_index); break;
4411 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4412 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4413 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4414 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4415 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4416 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4417 }
4418 }
4419 else
4420 {
4421 Map.clearscr(screen_index);
4422 }
4423 refresh(rALL);
4424 }
4425
4426 void set_screen_command::execute()
4427 {
4428 if (screen)
4429 {
4430 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4431 }
4432 else
4433 {
4434 Map.clearscr(screen_index);
4435 }
4436 refresh(rALL);
4437 }
4438
4439 void set_screen_command::undo()
4440 {
4441 if (prev_screen)
4442 {
4443 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4444 }
4445 else
4446 {
4447 Map.clearscr(screen_index);
4448 }
4449 refresh(rALL);
4450 }
4451
4452 int set_screen_command::size()
4453 {
4454 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4455 }
4456
4457 static std::shared_ptr<list_command> current_list_command;
4458 void zmap::StartListCommand()
4459 {
4460 ASSERT(!current_list_command);
4461 current_list_command.reset(new list_command);
4462 }
4463
4464 void zmap::FinishListCommand()
4465 {
4466 if (current_list_command->commands.size() == 1)
4467 {
4468 undo_stack.push_back(current_list_command->commands[0]);
4469 }
4470 else if (current_list_command->commands.size() > 1)
4471 {
4472 undo_stack.push_back(current_list_command);
4473 }
4474 CapCommandHistory();
4475 current_list_command = nullptr;
4476 }
4477
4478 void zmap::RevokeListCommand()
4479 {
4480 current_list_command->undo();
4481 current_list_command = nullptr;
4482 }
4483
4484 bool zmap::InListCommand() const
4485 {
4486 return current_list_command ? true : false;
4487 }
4488
4489 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4490 {
4491 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4492 if (!skip_execute) command->execute();
4493 if (current_list_command)
4494 {
4495 current_list_command->commands.push_back(command);
4496 if (current_list_command->commands.size() == 1)
4497 {
4498 current_list_command->cursor = command->cursor;
4499 }
4500 }
4501 else
4502 {
4503 undo_stack.push_back(command);
4504 CapCommandHistory();
4505 }
4506 saved = false;
4507 }
4508
4509 void zmap::UndoCommand()
4510 {
4511 if (undo_stack.size() <= 0) return;
4512
4513 // If not currently looking at the associated screen, first change the view
4514 // and wait for the next call to actually undo this command.
4515 auto command = undo_stack.back();
4516 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4517 {
4518 setCursor(command.get()->cursor);
4519 return;
4520 }
4521
4522 command->undo();
4523 redo_stack.push(command);
4524 undo_stack.pop_back();
4525 saved = false;
4526 }
4527
4528 void zmap::RedoCommand()
4529 {
4530 if (redo_stack.size() <= 0) return;
4531
4532 // If not currently selected the associated screen, first change the cursor
4533 // and wait for the next call to actually execute this command.
4534 auto command = redo_stack.top();
4535 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4536 {
4537 setCursor(command.get()->cursor);
4538 return;
4539 }
4540
4541 command->execute();
4542 undo_stack.push_back(command);
4543 redo_stack.pop();
4544 saved = false;
4545 }
4546
4547 11 void zmap::ClearCommandHistory()
4548 {
4549 11 current_list_command = nullptr;
4550 11 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4551 11 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4552 11 }
4553
4554 // Extra amount is from mapscr's vectors.
4555 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4556 // Allow the undo system to use roughly 100 MB of memory.
4557 // This doesn't count the memory used by commands that don't store a mapscr,
4558 // but that should be negligible.
4559 12 static int max_command_size = 100e6 / size_of_mapscr;
4560 void zmap::CapCommandHistory()
4561 {
4562 int size;
4563 do
4564 {
4565 size = 0;
4566 for (auto command : undo_stack)
4567 {
4568 size += command->size();
4569 }
4570 if (size > max_command_size) undo_stack.pop_front();
4571 } while (size > max_command_size);
4572 }
4573
4574 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4575 {
4576 if (!pos.is_valid(cursor))
4577 return;
4578
4579 int map = cursor.map;
4580 int screen = cursor.viewscr + pos.screen_offset();
4581 if (!AbsoluteScr(map, screen))
4582 return;
4583
4584 if (CurrentLayer)
4585 {
4586 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4587 map = scr->layermap[CurrentLayer-1]-1;
4588 screen = scr->layerscreen[CurrentLayer-1];
4589 }
4590 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4591 }
4592
4593 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4594 {
4595 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4596 if (!mapscr_ptr) return;
4597
4598 std::shared_ptr<set_combo_command> command(new set_combo_command);
4599 command->cursor = cursor;
4600 command->map = map;
4601 command->scr = scr;
4602 command->pos = pos;
4603 command->combo = combo;
4604 command->cset = cset;
4605 command->prev_combo = mapscr_ptr->data[pos];
4606 command->prev_cset = mapscr_ptr->cset[pos];
4607 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4608 {
4609 // nothing to do...
4610 return;
4611 }
4612
4613 ExecuteCommand(command);
4614 }
4615
4616 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4617 {
4618 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4619 if(!mapscr_ptr) return;
4620
4621 mapscr_ptr->ensureFFC(i);
4622
4623 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4624
4625 std::array<int, 8> initd_arr;
4626 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4627
4628 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4629
4630 command->cursor = cursor;
4631 command->map = map;
4632 command->scr = scr;
4633 command->i = i;
4634 command->data = data;
4635 command->prev_data = prev_data;
4636 if (data == prev_data)
4637 {
4638 // nothing to do...
4639 return;
4640 }
4641
4642 ExecuteCommand(command);
4643 }
4644
4645 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4646 {
4647 if (!pos.is_valid(cursor))
4648 return;
4649
4650 int map = cursor.map;
4651 int screen = cursor.viewscr + pos.screen_offset();
4652 if (!AbsoluteScr(map, screen))
4653 return;
4654
4655 if (CurrentLayer)
4656 {
4657 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4658 map = scr->layermap[CurrentLayer-1]-1;
4659 screen = scr->layerscreen[CurrentLayer-1];
4660 }
4661 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4662 }
4663
4664 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4665 {
4666 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4667 if(!mapscr_ptr) return;
4668
4669 std::shared_ptr<set_flag_command> command(new set_flag_command);
4670 command->cursor = cursor;
4671 command->map = map;
4672 command->scr = scr;
4673 command->pos = pos;
4674 command->flag = flag;
4675 command->prev_flag = mapscr_ptr->sflag[pos];
4676 if (command->flag == command->prev_flag)
4677 {
4678 // nothing to do...
4679 return;
4680 }
4681
4682 ExecuteCommand(command);
4683 }
4684
4685 void zmap::DoSetDoorCommand(int scr, int side, int door)
4686 {
4687 if(screens[scr].door[side] == door)
4688 return;
4689 std::shared_ptr<set_door_command> command(new set_door_command);
4690 command->cursor = cursor;
4691 command->side = side;
4692 command->door = door;
4693 command->prev_door = screens[scr].door[side];
4694
4695 ExecuteCommand(command);
4696 }
4697 void zmap::DoSetDCSCommand(int dcs)
4698 {
4699 if(screens[cursor.screen].door_combo_set == dcs)
4700 return;
4701 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4702 command->cursor = cursor;
4703 command->dcs = dcs;
4704 command->prev_dcs = screens[cursor.screen].door_combo_set;
4705
4706 ExecuteCommand(command);
4707 }
4708
4709 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4710 {
4711 if (screen == -1)
4712 screen = cursor.screen;
4713
4714 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4715 command->cursor = cursor;
4716 command->type = type;
4717 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4718 command->screen_index = screen;
4719
4720 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4721 {
4722 for (int i=0; i < 128; i++)
4723 {
4724 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4725 }
4726 }
4727 else
4728 {
4729 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4730 }
4731
4732 ExecuteCommand(command);
4733 }
4734
4735 void zmap::DoClearScreenCommand(int screen)
4736 {
4737 std::shared_ptr<set_screen_command> command(new set_screen_command);
4738 command->cursor = cursor;
4739 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4740 command->screen = std::shared_ptr<mapscr>(nullptr);
4741 command->screen_index = screen;
4742
4743 ExecuteCommand(command);
4744 }
4745
4746 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4747 {
4748 std::shared_ptr<set_screen_command> command(new set_screen_command);
4749 command->cursor = cursor;
4750 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4751 Template(floorcombo, floorcset, screen);
4752 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4753
4754 ExecuteCommand(command, true);
4755 }
4756
4757 void zmap::Copy(int scr)
4758 {
4759 if(screens[scr].valid&mVALID)
4760 {
4761 copy_mapscr(&copymapscr, &screens[scr]);
4762 //copymapscr=screens[scr];
4763 can_paste=true;
4764 copymap=cursor.map;
4765 copyscr=scr;
4766 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4767 copyffc = -1;
4768 }
4769 }
4770
4771 void zmap::CopyFFC(int32_t screen, int32_t n)
4772 {
4773 if(screens[screen].valid&mVALID)
4774 {
4775 copy_mapscr(&copymapscr, &screens[screen]);
4776 // Can't paste the screen itself
4777 can_paste = false;
4778 copymap=cursor.map;
4779 copyscr=screen;
4780 copyffc = n;
4781 }
4782 }
4783
4784 void zmap::Paste(const mapscr& copymapscr, int screen)
4785 {
4786 if(can_paste)
4787 {
4788 int32_t oldcolor=getcolor();
4789
4790 if(!(screens[screen].valid&mVALID))
4791 {
4792 screens[screen].valid |= mVALID;
4793 screens[screen].color = copymapscr.color;
4794 }
4795
4796 screens[screen].door_combo_set = copymapscr.door_combo_set;
4797
4798 for(int32_t i=0; i<4; i++)
4799 {
4800 screens[screen].door[i]=copymapscr.door[i];
4801 }
4802
4803 for(int32_t i=0; i<176; i++)
4804 {
4805 screens[screen].data[i] = copymapscr.data[i];
4806 screens[screen].cset[i] = copymapscr.cset[i];
4807 screens[screen].sflag[i] = copymapscr.sflag[i];
4808 }
4809
4810 int32_t newcolor=getcolor();
4811 loadlvlpal(newcolor);
4812
4813 if(newcolor!=oldcolor)
4814 {
4815 rebuild_trans_table();
4816 }
4817
4818 saved=false;
4819 }
4820 }
4821
4822 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4823 {
4824 if(can_paste)
4825 {
4826 screens[screen].undercombo = copymapscr.undercombo;
4827 screens[screen].undercset = copymapscr.undercset;
4828 saved=false;
4829 }
4830 }
4831
4832 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4833 {
4834 if(can_paste)
4835 {
4836 for(int32_t i=0; i<128; i++)
4837 {
4838 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4839 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4840 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4841 }
4842
4843 saved=false;
4844 }
4845 }
4846
4847 // TODO const mapscr& copymapscr
4848 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4849 {
4850 if(can_paste)
4851 {
4852 screens[screen].ffcs = copymapscr.ffcs;
4853 screens[screen].ffcCountMarkDirty();
4854 saved=false;
4855 }
4856 }
4857
4858 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4859 {
4860 if(can_paste)
4861 {
4862 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4863
4864 for(int32_t i=0; i<4; i++)
4865 {
4866 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4867 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4868 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4869 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4870 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4871 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4872 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4873 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4874 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4875 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4876 }
4877
4878 saved=false;
4879 }
4880 }
4881
4882 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4883 {
4884 if(can_paste)
4885 {
4886 screens[screen].csensitive = copymapscr.csensitive;
4887 screens[screen].oceansfx = copymapscr.oceansfx;
4888 screens[screen].bosssfx = copymapscr.bosssfx;
4889 screens[screen].secretsfx = copymapscr.secretsfx;
4890 screens[screen].holdupsfx = copymapscr.holdupsfx;
4891 screens[screen].flags = copymapscr.flags;
4892 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4893 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4894 screens[screen].flags3 = copymapscr.flags3;
4895 screens[screen].flags4 = copymapscr.flags4;
4896 screens[screen].flags5 = copymapscr.flags5;
4897 screens[screen].flags6 = copymapscr.flags6;
4898 screens[screen].flags7 = copymapscr.flags7;
4899 screens[screen].flags8 = copymapscr.flags8;
4900 screens[screen].flags9 = copymapscr.flags9;
4901 screens[screen].flags10 = copymapscr.flags10;
4902 screens[screen].flags11 = copymapscr.flags11;
4903 screens[screen].item = copymapscr.item;
4904 screens[screen].hasitem = copymapscr.hasitem;
4905 screens[screen].itemx = copymapscr.itemx;
4906 screens[screen].itemy = copymapscr.itemy;
4907 screens[screen].nextmap = copymapscr.nextmap;
4908 screens[screen].nextscr = copymapscr.nextscr;
4909 screens[screen].nocarry = copymapscr.nocarry;
4910 screens[screen].noreset = copymapscr.noreset;
4911 screens[screen].path[0] = copymapscr.path[0];
4912 screens[screen].path[1] = copymapscr.path[1];
4913 screens[screen].path[2] = copymapscr.path[2];
4914 screens[screen].path[3] = copymapscr.path[3];
4915 screens[screen].pattern = copymapscr.pattern;
4916 screens[screen].exitdir = copymapscr.exitdir;
4917 screens[screen].screen_midi = copymapscr.screen_midi;
4918 screens[screen].stairx = copymapscr.stairx;
4919 screens[screen].stairy = copymapscr.stairy;
4920 screens[screen].timedwarptics = copymapscr.timedwarptics;
4921 saved=false;
4922 }
4923 }
4924
4925 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4926 {
4927 if(can_paste)
4928 {
4929 screens[screen].warpreturnc = copymapscr.warpreturnc;
4930 screens[screen].warparrivalx = copymapscr.warparrivalx;
4931 screens[screen].warparrivaly = copymapscr.warparrivaly;
4932
4933 for(int32_t i=0; i<4; i++)
4934 {
4935 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4936 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4937 }
4938
4939 saved=false;
4940 }
4941 }
4942
4943 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4944 {
4945 if(can_paste)
4946 {
4947 for(int32_t i=0; i<4; i++)
4948 screens[screen].door[i] = copymapscr.door[i];
4949
4950 screens[screen].door_combo_set = copymapscr.door_combo_set;
4951 saved=false;
4952 }
4953 }
4954
4955 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4956 {
4957 if(can_paste)
4958 {
4959 for(int32_t i=0; i<6; i++)
4960 {
4961 screens[screen].layermap[i] = copymapscr.layermap[i];
4962 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4963 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4964 }
4965
4966 saved=false;
4967 }
4968 }
4969
4970 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4971 {
4972 if(can_paste)
4973 {
4974 screens[screen].room = copymapscr.room;
4975 screens[screen].catchall = copymapscr.catchall;
4976 saved=false;
4977 }
4978 }
4979
4980 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4981 {
4982 if(can_paste)
4983 {
4984 screens[screen].guy = copymapscr.guy;
4985 screens[screen].guytile = copymapscr.guytile;
4986 screens[screen].guycs = copymapscr.guycs;
4987 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4988 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4989 screens[screen].str = copymapscr.str;
4990 saved=false;
4991 }
4992 }
4993
4994 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4995 {
4996 if(can_paste)
4997 {
4998 int32_t oldcolor=getcolor();
4999 screens[screen].color = copymapscr.color;
5000 int32_t newcolor=getcolor();
5001 loadlvlpal(newcolor);
5002
5003 screens[screen].valid|=mVALID;
5004
5005 if(newcolor!=oldcolor)
5006 {
5007 rebuild_trans_table();
5008 }
5009
5010 saved=false;
5011 }
5012 }
5013
5014 void zmap::PasteAll(const mapscr& copymapscr, int screen)
5015 {
5016 if(can_paste)
5017 {
5018 int32_t oldcolor=getcolor();
5019 copy_mapscr(&screens[screen], &copymapscr);
5020 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
5021 //screens[screen]=copymapscr;
5022 int32_t newcolor=getcolor();
5023 loadlvlpal(newcolor);
5024
5025 screens[screen].valid|=mVALID;
5026
5027 if(newcolor!=oldcolor)
5028 {
5029 rebuild_trans_table();
5030 }
5031
5032 saved=false;
5033 }
5034 }
5035
5036
5037 void zmap::PasteToAll(const mapscr& copymapscr)
5038 {
5039 if(can_paste)
5040 {
5041 int32_t oldcolor=getcolor();
5042
5043 for(int32_t x=0; x<128; x++)
5044 {
5045 if(!(screens[x].valid&mVALID))
5046 {
5047 screens[x].valid |= mVALID;
5048 screens[x].color = copymapscr.color;
5049 }
5050
5051 for(int32_t i=0; i<176; i++)
5052 {
5053 screens[x].data[i] = copymapscr.data[i];
5054 screens[x].cset[i] = copymapscr.cset[i];
5055 screens[x].sflag[i] = copymapscr.sflag[i];
5056 }
5057 }
5058
5059 int32_t newcolor=getcolor();
5060 loadlvlpal(newcolor);
5061
5062 if(!(screens[cursor.screen].valid&mVALID))
5063 {
5064 newcolor=-1;
5065 }
5066
5067 if(newcolor!=oldcolor)
5068 {
5069 rebuild_trans_table();
5070 }
5071
5072 saved=false;
5073 }
5074 }
5075
5076 void zmap::PasteAllToAll(const mapscr& copymapscr)
5077 {
5078 if(can_paste)
5079 {
5080 int32_t oldcolor=getcolor();
5081
5082 for(int32_t x=0; x<128; x++)
5083 {
5084 copy_mapscr(&screens[x], &copymapscr);
5085 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
5086 //screens[x]=copymapscr;
5087 }
5088
5089 int32_t newcolor=getcolor();
5090 loadlvlpal(newcolor);
5091
5092 if(!(screens[cursor.screen].valid&mVALID))
5093 {
5094 newcolor=-1;
5095 }
5096
5097 if(newcolor!=oldcolor)
5098 {
5099 rebuild_trans_table();
5100 }
5101
5102 saved=false;
5103 }
5104 }
5105
5106 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
5107 {
5108 if(can_paste)
5109 {
5110 for(int32_t i=0; i<10; i++)
5111 screens[screen].enemy[i]=copymapscr.enemy[i];
5112 }
5113 }
5114
5115 void zmap::setCopyFFC(int32_t n)
5116 {
5117 copyffc = n;
5118 }
5119
5120 void zmap::update_combo_cycling()
5121 {
5122 if(!prv_mode||!prv_cmbcycle)
5123 {
5124 return;
5125 }
5126
5127 int32_t x;
5128 int32_t newdata[176];
5129 int32_t newcset[176];
5130 bool restartanim[MAXCOMBOS] = {0};
5131
5132 for(int32_t i=0; i<176; i++)
5133 {
5134 newdata[i]=-1;
5135 newcset[i]=-1;
5136
5137 x=prvscr.data[i];
5138
5139 //time to restart
5140 if((combobuf[x].aclk>=combobuf[x].speed) &&
5141 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5142 combobuf[x].can_cycle())
5143 {
5144 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5145 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5146
5147 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5148 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5149 int32_t c = newdata[i];
5150
5151 if(combobuf[c].animflags & AF_CYCLE)
5152 {
5153 restartanim[c]=true;
5154 }
5155 }
5156 }
5157
5158 for(int32_t i=0; i<176; i++)
5159 {
5160 x=prvscr.data[i];
5161
5162 //time to restart
5163 if((combobuf[x].aclk>=combobuf[x].speed) &&
5164 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5165 combobuf[x].can_cycle())
5166 {
5167 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5168 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5169
5170 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5171 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5172 int32_t c = newdata[i];
5173
5174 if(combobuf[c].animflags & AF_CYCLE)
5175 {
5176 restartanim[c]=true;
5177 }
5178 }
5179 }
5180
5181 for(int32_t i=0; i<176; i++)
5182 {
5183 if(newdata[i]==-1)
5184 continue;
5185
5186 prvscr.data[i]=newdata[i];
5187 prvscr.cset[i]=newcset[i];
5188 }
5189
5190 word maxffc = prvscr.numFFC();
5191 for(word i=0; i<maxffc; i++)
5192 {
5193 ffcdata& ffc = prvscr.ffcs[i];
5194 newcombo const& cmb = combobuf[ffc.data];
5195
5196 //time to restart
5197 if((cmb.aclk>=cmb.speed) &&
5198 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5199 cmb.can_cycle())
5200 {
5201 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5202 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5203
5204 if(!(cmb.animflags & AF_CYCLENOCSET))
5205 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5206
5207 if(combobuf[ffc.data].animflags & AF_CYCLE)
5208 {
5209 restartanim[ffc.data]=true;
5210 }
5211 prvscr.ffcs[i].data = ffc.data;
5212 prvscr.ffcs[i].cset=ffc.cset;
5213 }
5214 }
5215
5216
5217 if(get_qr(qr_CMBCYCLELAYERS))
5218 {
5219 for(int32_t j=0; j<6; j++)
5220 {
5221 if(!prvlayers[j].valid)
5222 continue;
5223
5224 for(int32_t i=0; i<176; i++)
5225 {
5226 newdata[i]=-1;
5227 newcset[i]=-1;
5228
5229 x=(prvlayers[j]).data[i];
5230
5231 //time to restart
5232 if((combobuf[x].aclk>=combobuf[x].speed) &&
5233 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5234 combobuf[x].can_cycle())
5235 {
5236 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5237 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5238
5239 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5240 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5241 int32_t c = newdata[i];
5242
5243 if(combobuf[c].animflags & AF_CYCLE)
5244 {
5245 restartanim[c]=true;
5246 }
5247 }
5248 }
5249
5250 for(int32_t i=0; i<176; i++)
5251 {
5252 x=(prvlayers[j]).data[i];
5253
5254 //time to restart
5255 if((combobuf[x].aclk>=combobuf[x].speed) &&
5256 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5257 combobuf[x].can_cycle())
5258 {
5259 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5260 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5261
5262 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5263 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5264 int32_t c = newdata[i];
5265
5266 if(combobuf[c].animflags & AF_CYCLE)
5267 {
5268 restartanim[c]=true;
5269 }
5270 }
5271 }
5272
5273 for(int32_t i=0; i<176; i++)
5274 {
5275 if(newdata[i]==-1)
5276 continue;
5277
5278 prvlayers[j].data[i]=newdata[i];
5279 prvlayers[j].cset[i]=newcset[i];
5280 }
5281 }
5282 }
5283
5284 for(int32_t i=0; i<MAXCOMBOS; i++)
5285 {
5286 if(restartanim[i])
5287 {
5288 combobuf[i].tile = combobuf[i].o_tile;
5289 combobuf[i].cur_frame=0;
5290 combobuf[i].aclk = 0;
5291 }
5292 }
5293 }
5294
5295 void zmap::update_freeform_combos()
5296 {
5297 if(!prv_mode||!prv_cmbcycle)
5298 {
5299 return;
5300 }
5301
5302 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5303 word maxffc = prvscr.numFFC();
5304 for(int32_t i=0; i<maxffc; i++)
5305 {
5306 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5307 {
5308 for(int32_t j=0; j<maxffc; j++)
5309 {
5310 if(i!=j)
5311 {
5312 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5313 {
5314 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5315 {
5316 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5317 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5318 {
5319 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5320 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5321 if(prvscr.ffcs[j].flags&ffc_changethis)
5322 {
5323 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5324 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5325 }
5326
5327 if(prvscr.ffcs[j].flags&ffc_changenext)
5328 prvscr.ffcs[i].data += 1;
5329
5330 if(prvscr.ffcs[j].flags&ffc_changeprev)
5331 prvscr.ffcs[i].data -= 1;
5332
5333 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5334 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5335 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5336
5337 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5338 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5339 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5340 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5341
5342 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5343 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5344 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5345 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5346 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5347
5348 if(prvscr.ffcs[i].flags&ffc_carryover)
5349 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5350 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5351
5352 prvscr.ffcs[i].flags&=~ffc_changer;
5353 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5354 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5355
5356 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5357 {
5358 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5359 }
5360
5361 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5362 {
5363 int32_t k=0;
5364
5365 if(prvscr.ffcs[j].flags&ffc_swapnext)
5366 k=j<(MAXFFCS-1)?j+1:0;
5367
5368 if(prvscr.ffcs[j].flags&ffc_swapprev)
5369 k=j>0?j-1:(MAXFFCS-1);
5370
5371 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5372 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5373 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5374 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5375 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5376 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5377 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5378 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5379 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5380 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5381 }
5382 }
5383 }
5384 }
5385 }
5386 }
5387
5388 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5389 {
5390 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5391 {
5392 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5393 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5394 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5395 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5396 }
5397 else
5398 {
5399 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5400 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5401 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5402 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5403 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5404 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5405
5406 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5407 {
5408 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5409
5410 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5411
5412 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5413
5414 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5415 }
5416 }
5417 }
5418 else
5419 {
5420 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5421 prvscr.ffcs[i].delay--;
5422 }
5423
5424 if(prvscr.ffcs[i].x<-32)
5425 {
5426 if(prvscr.flags6&fWRAPAROUNDFF)
5427 {
5428 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5429 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5430 }
5431 else
5432 {
5433 prvscr.ffcs[i].data = 0;
5434 prvscr.ffcs[i].flags&=~ffc_carryover;
5435 }
5436 }
5437
5438 if(prvscr.ffcs[i].y<-32)
5439 {
5440 if(prvscr.flags6&fWRAPAROUNDFF)
5441 {
5442 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5443 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5444 }
5445 else
5446 {
5447 prvscr.ffcs[i].data = 0;
5448 prvscr.ffcs[i].flags&=~ffc_carryover;
5449 }
5450 }
5451
5452 if(prvscr.ffcs[i].x>=288)
5453 {
5454 if(prvscr.flags6&fWRAPAROUNDFF)
5455 {
5456 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5457 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5458 }
5459 else
5460 {
5461 prvscr.ffcs[i].data = 0;
5462 prvscr.ffcs[i].flags&=~ffc_carryover;
5463 }
5464 }
5465
5466 if(prvscr.ffcs[i].y>=208)
5467 {
5468 if(prvscr.flags6&fWRAPAROUNDFF)
5469 {
5470 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5471 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5472 }
5473 else
5474 {
5475 prvscr.ffcs[i].data = 0;
5476 prvscr.ffcs[i].flags&=~ffc_carryover;
5477 }
5478 }
5479
5480 }
5481 }
5482 }
5483
5484 void zmap::goto_dmapscr(int dmap, int scr)
5485 {
5486 setCurrMap(DMaps[dmap].map);
5487 setCurrScr(scr+DMaps[dmap].xoff);
5488 }
5489 void zmap::goto_mapscr(int map, int scr)
5490 {
5491 setCurrMap(map);
5492 setCurrScr(scr);
5493 }
5494
5495 void zmap::dowarp(int32_t type, int32_t index)
5496 {
5497 set_warpback();
5498 if(type==0)
5499 {
5500
5501 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5502 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5503
5504 switch(screens[cursor.screen].tilewarptype[index])
5505 {
5506 case wtCAVE:
5507 case wtNOWARP:
5508 break;
5509
5510 default:
5511 goto_dmapscr(dmap, scr);
5512 break;
5513 }
5514 }
5515 else if(type==1)
5516 {
5517 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5518 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5519
5520 switch(screens[cursor.screen].sidewarptype[index])
5521 {
5522 case wtCAVE:
5523 case wtNOWARP:
5524 break;
5525
5526 default:
5527 goto_dmapscr(dmap, scr);
5528 break;
5529 }
5530 }
5531 }
5532
5533 extern int32_t prv_twon;
5534
5535 void zmap::prv_dowarp(int32_t type, int32_t index)
5536 {
5537 if(type==0)
5538 {
5539
5540 int32_t dmap=prvscr.tilewarpdmap[index];
5541 int32_t scr=prvscr.tilewarpscr[index];
5542
5543 switch(prvscr.tilewarptype[index])
5544 {
5545 case wtCAVE:
5546 case wtNOWARP:
5547 break;
5548
5549 default:
5550 //setCurrMap(DMaps[dmap].map);
5551 //setCurrScr(scr+DMaps[dmap].xoff);
5552 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5553 loadlvlpal(getcolor());
5554 rebuild_trans_table();
5555 //prv_cmbcycle=0;
5556 break;
5557 }
5558 }
5559 else if(type==1)
5560 {
5561 int32_t dmap=prvscr.sidewarpdmap[index];
5562 int32_t scr=prvscr.sidewarpscr[index];
5563
5564 switch(prvscr.sidewarptype[index])
5565 {
5566 case wtCAVE:
5567 case wtNOWARP:
5568 break;
5569
5570 default:
5571 //setCurrMap(DMaps[dmap].map);
5572 //setCurrScr(scr+DMaps[dmap].xoff);
5573 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5574 loadlvlpal(getcolor());
5575 rebuild_trans_table();
5576 //prv_cmbcycle=0;
5577 break;
5578 }
5579 }
5580
5581 if(prv_twon)
5582 {
5583 prv_time=get_prvscr()->timedwarptics;
5584 }
5585 }
5586
5587 void zmap::dowarp2(int32_t ring,int32_t index)
5588 {
5589 set_warpback();
5590 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5591 }
5592
5593 void zmap::set_warpback()
5594 {
5595 warpbackmap = cursor.map;
5596 warpbackscreen = cursor.screen;
5597 }
5598 bool zmap::has_warpback()
5599 {
5600 return warpbackmap && warpbackscreen
5601 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5602 }
5603 void zmap::warpback()
5604 {
5605 if(!has_warpback())
5606 return;
5607
5608 int m = cursor.map, s = cursor.screen;
5609 goto_mapscr(*warpbackmap, *warpbackscreen);
5610 warpbackmap = m;
5611 warpbackscreen = s;
5612 }
5613
5614 bool save_msgstrs(const char *path)
5615 {
5616 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5617
5618 if(!f)
5619 {
5620 return false;
5621 }
5622
5623 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5624 {
5625 pack_fclose(f);
5626 return true;
5627 }
5628
5629 pack_fclose(f);
5630 return false;
5631 }
5632
5633 1 bool save_strings_tsv(const char *path)
5634 {
5635 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5636
5637
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5638 {
5639 return false;
5640 }
5641
5642
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5643 {
5644 1 pack_fclose(f);
5645 1 return true;
5646 }
5647
5648 pack_fclose(f);
5649 return false;
5650 1 }
5651
5652 bool save_msgstrs_text(const char *path)
5653 {
5654 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5655
5656 if(!f)
5657 {
5658 return false;
5659 }
5660
5661 if(writestrings_text(f)==0)
5662 {
5663 pack_fclose(f);
5664 return true;
5665 }
5666
5667 pack_fclose(f);
5668 return false;
5669 }
5670
5671 bool load_msgstrs(const char *path, int32_t startstring)
5672 {
5673 //these are here to bypass compiler warnings about unused arguments
5674 startstring=startstring;
5675
5676 dword section_id;
5677 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5678
5679 if(!f)
5680 {
5681 return false;
5682 }
5683
5684 if(!p_mgetl(&section_id,f))
5685 {
5686 return false;
5687 }
5688
5689 if(section_id==ID_STRINGS)
5690 {
5691 if(readstrings(f, &header)==0)
5692 {
5693 pack_fclose(f);
5694 return true;
5695 }
5696 else
5697 {
5698 pack_fclose(f);
5699 return false;
5700 }
5701 }
5702
5703 pack_fclose(f);
5704 return false;
5705 }
5706
5707 bool load_strings_tsv(const char *path)
5708 {
5709 try
5710 {
5711 parse_strings_tsv(util::read_text_file(path));
5712 }
5713 catch (std::exception& ex)
5714 {
5715 InfoDialog("Import .tsv Error", ex.what()).show();
5716 return false;
5717 }
5718 return true;
5719 }
5720
5721 bool save_pals(const char *path)
5722 {
5723 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5724
5725 if(!f)
5726 {
5727 return false;
5728 }
5729
5730 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5731 {
5732 pack_fclose(f);
5733 return true;
5734 }
5735
5736 pack_fclose(f);
5737 return false;
5738 }
5739
5740 bool load_pals(const char *path, int32_t startcset)
5741 {
5742 dword section_id;
5743 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5744
5745 if(!f)
5746 {
5747 return false;
5748 }
5749
5750 if(!p_mgetl(&section_id,f))
5751 {
5752 return false;
5753 }
5754
5755 if(section_id==ID_CSETS)
5756 {
5757 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5758 {
5759 pack_fclose(f);
5760 loadlvlpal(Color);
5761 return true;
5762 }
5763 else
5764 {
5765 pack_fclose(f);
5766 return false;
5767 }
5768 }
5769
5770 return false;
5771 }
5772
5773 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5774 bool save_guys(const char *path)
5775 {
5776 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5777
5778 if(!f)
5779 {
5780 return false;
5781 }
5782
5783 /*
5784 int32_t id = ID_GUYS;
5785 if(!p_mputl(id,f))
5786 {
5787 return false;
5788 }
5789 */
5790
5791 zquestheader h;
5792 h.zelda_version = 0x250;
5793 h.build = 21;
5794
5795 if(writeguys(f, &h)==0)
5796 {
5797 pack_fclose(f);
5798 return true;
5799 }
5800
5801 pack_fclose(f);
5802 return false;
5803 }
5804
5805 bool load_guys(const char *path)
5806 {
5807 dword section_id;
5808 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5809
5810 if(!f)
5811 {
5812 return false;
5813 }
5814
5815 if(!p_mgetl(&section_id,f))
5816 {
5817 pack_fclose(f);
5818 return false;
5819 }
5820
5821 zquestheader h;
5822 h.zelda_version = 0x250;
5823 h.build = 21;
5824
5825 if(section_id==ID_GUYS)
5826 {
5827 if(readguys(f, &h)==0)
5828 {
5829 pack_fclose(f);
5830 return true;
5831 }
5832 }
5833
5834 pack_fclose(f);
5835 return false;
5836 }
5837
5838
5839 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5840 bool save_combo_alias(const char *path)
5841 {
5842 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5843
5844 if(!f)
5845 {
5846 return false;
5847 }
5848
5849 zquestheader h;
5850 h.zelda_version = 0x250;
5851 h.build = 21;
5852
5853 if(writecomboaliases(f, 0, 0)==0)
5854 {
5855 pack_fclose(f);
5856 return true;
5857 }
5858
5859 pack_fclose(f);
5860 return false;
5861 }
5862
5863 bool load_combo_alias(const char *path)
5864 {
5865 dword section_id;
5866 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5867
5868 if(!f)
5869 {
5870 return false;
5871 }
5872
5873 if(!p_mgetl(&section_id,f))
5874 {
5875 pack_fclose(f);
5876 return false;
5877 }
5878
5879 zquestheader h;
5880 h.zelda_version = 0x250;
5881 h.build = 21;
5882
5883 if(section_id==ID_COMBOALIASES)
5884 {
5885 if(readcomboaliases(f, &h, 0, 0)==0)
5886 {
5887 pack_fclose(f);
5888 return true;
5889 }
5890 }
5891
5892 pack_fclose(f);
5893 return false;
5894 }
5895
5896 bool load_zgp(const char *path)
5897 {
5898 dword section_id;
5899 word section_version;
5900 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5901
5902 if(!f)
5903 return false;
5904
5905 if(!p_mgetl(&section_id,f))
5906 {
5907 pack_fclose(f);
5908 return false;
5909 }
5910
5911 if(section_id!=ID_GRAPHICSPACK)
5912 {
5913 pack_fclose(f);
5914 return false;
5915 }
5916
5917 //section version info
5918 if(!p_igetw(&section_version,f))
5919 {
5920 return 2;
5921 }
5922
5923 if(!read_deprecated_section_cversion(f))
5924 {
5925 return 3;
5926 }
5927
5928 //tiles
5929 if(!p_mgetl(&section_id,f))
5930 {
5931 pack_fclose(f);
5932 return false;
5933 }
5934
5935 if(section_id==ID_TILES)
5936 {
5937 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5938 {
5939 pack_fclose(f);
5940 init_tiles(true, &header);
5941 return false;
5942 }
5943 }
5944 else
5945 {
5946 pack_fclose(f);
5947 return false;
5948 }
5949
5950 //combos
5951 if(!p_mgetl(&section_id,f))
5952 {
5953 pack_fclose(f);
5954 return false;
5955 }
5956
5957 if(section_id==ID_COMBOS)
5958 {
5959 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5960 {
5961 pack_fclose(f);
5962 return false;
5963 }
5964 }
5965 else
5966 {
5967 pack_fclose(f);
5968 return false;
5969 }
5970
5971 //palettes
5972 if(!p_mgetl(&section_id,f))
5973 {
5974 pack_fclose(f);
5975 return false;
5976 }
5977
5978 if(section_id==ID_CSETS)
5979 {
5980 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5981 {
5982 pack_fclose(f);
5983 return false;
5984 }
5985 }
5986 else
5987 {
5988 pack_fclose(f);
5989 return false;
5990 }
5991
5992 //items
5993 if(!p_mgetl(&section_id,f))
5994 {
5995 pack_fclose(f);
5996 return false;
5997 }
5998
5999 if(section_id==ID_ITEMS)
6000 {
6001 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
6002 {
6003 pack_fclose(f);
6004 return false;
6005 }
6006 }
6007 else
6008 {
6009 pack_fclose(f);
6010 return false;
6011 }
6012
6013 //weapons
6014 if(!p_mgetl(&section_id,f))
6015 {
6016 pack_fclose(f);
6017 return false;
6018 }
6019
6020 if(section_id==ID_WEAPONS)
6021 {
6022 if(readweapons(f, &header)!=0)
6023 {
6024 pack_fclose(f);
6025 return false;
6026 }
6027 }
6028 else
6029 {
6030 pack_fclose(f);
6031 return false;
6032 }
6033
6034 //read the triforce pieces info and make sure it worked
6035 //really do this?
6036
6037 //read the game icons info and make sure it worked
6038 if(!p_mgetl(&section_id,f))
6039 {
6040 pack_fclose(f);
6041 return false;
6042 }
6043
6044 if(section_id==ID_ICONS)
6045 {
6046 if(readgameicons(f, &header, &QMisc)!=0)
6047 {
6048 pack_fclose(f);
6049 return false;
6050 }
6051 }
6052 else
6053 {
6054 pack_fclose(f);
6055 return false;
6056 }
6057
6058 //read the misc colors info and map styles info and make sure it worked
6059 if(!p_mgetl(&section_id,f))
6060 {
6061 pack_fclose(f);
6062 return false;
6063 }
6064
6065 if(section_id==ID_COLORS)
6066 {
6067 if(readmisccolors(f, &header, &QMisc)!=0)
6068 {
6069 pack_fclose(f);
6070 return false;
6071 }
6072 }
6073 else
6074 {
6075 pack_fclose(f);
6076 return false;
6077 }
6078
6079 //read the door combo sets and make sure it worked
6080 if(!p_mgetl(&section_id,f))
6081 {
6082 pack_fclose(f);
6083 return false;
6084 }
6085
6086 if(section_id==ID_DOORS)
6087 {
6088 if(readdoorcombosets(f, &header)!=0)
6089 {
6090 pack_fclose(f);
6091 return false;
6092 }
6093 }
6094 else
6095 {
6096 pack_fclose(f);
6097 return false;
6098 }
6099
6100 //read the template screens and make sure it worked
6101 //really do this?
6102
6103 //yay! it worked! close the file and say everything was ok.
6104 loadlvlpal(Color);
6105 setup_combo_animations();
6106 setup_combo_animations2();
6107 pack_fclose(f);
6108 return true;
6109 }
6110
6111 bool save_zgp(const char *path)
6112 {
6113 reset_combo_animations();
6114 reset_combo_animations2();
6115
6116 //open the file
6117 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6118
6119 if(!f)
6120 return false;
6121
6122 dword section_id=ID_GRAPHICSPACK;
6123 dword section_version=V_GRAPHICSPACK;
6124
6125 //section id
6126 if(!p_mputl(section_id,f))
6127 {
6128 return 1;
6129 }
6130
6131 //section version info
6132 if(!p_iputw(section_version,f))
6133 {
6134 return 2;
6135 }
6136
6137 if(!write_deprecated_section_cversion(section_version,f))
6138 {
6139 return 3;
6140 }
6141
6142 //tiles
6143 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6144 {
6145 pack_fclose(f);
6146 return false;
6147 }
6148
6149 //combos
6150 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6151 {
6152 pack_fclose(f);
6153 return false;
6154 }
6155
6156 //palettes
6157 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6158 {
6159 pack_fclose(f);
6160 return false;
6161 }
6162
6163 //items
6164 if(writeitems(f, &header)!=0)
6165 {
6166 pack_fclose(f);
6167 return false;
6168 }
6169
6170 //weapons
6171 if(writeweapons(f, &header)!=0)
6172 {
6173 pack_fclose(f);
6174 return false;
6175 }
6176
6177 //write the triforce pieces info and make sure it worked
6178 //really do this?
6179
6180 //write the game icons info and make sure it worked
6181 if(writegameicons(f, &header)!=0)
6182 {
6183 pack_fclose(f);
6184 return false;
6185 }
6186
6187 //write the misc colors info and map styles info and make sure it worked
6188 if(writemisccolors(f, &header)!=0)
6189 {
6190 pack_fclose(f);
6191 return false;
6192 }
6193
6194 //write the door combo sets and make sure it worked
6195 if(writedoorcombosets(f, &header)!=0)
6196 {
6197 pack_fclose(f);
6198 return false;
6199 }
6200
6201 //write the template screens and make sure it worked
6202 //really do this?
6203
6204 pack_fclose(f);
6205 return true;
6206 }
6207
6208 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6209 {
6210 //open the file
6211 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6212
6213 if(!f)
6214 return false;
6215
6216 dword section_id=ID_SUBSCREEN;
6217 dword s_version=V_SUBSCREEN;
6218
6219 if(!p_mputl(section_id,f))
6220 {
6221 pack_fclose(f);
6222 return false;
6223 }
6224
6225 if(!p_iputw(s_version,f))
6226 {
6227 pack_fclose(f);
6228 return false;
6229 }
6230
6231 if(!write_deprecated_section_cversion(s_version,f))
6232 {
6233 pack_fclose(f);
6234 return false;
6235 }
6236
6237 if(savefrom.write(f))
6238 {
6239 pack_fclose(f);
6240 return false;
6241 }
6242
6243 pack_fclose(f);
6244 return true;
6245 }
6246
6247 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6248 {
6249 //open the file
6250 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6251
6252 if(!f)
6253 return false;
6254
6255 dword section_id;
6256 dword s_version;
6257
6258 if(!p_mgetl(&section_id,f))
6259 {
6260 pack_fclose(f);
6261 return false;
6262 }
6263
6264 if(section_id!=ID_SUBSCREEN)
6265 {
6266 pack_fclose(f);
6267 return false;
6268 }
6269
6270 if(!p_igetw(&s_version,f))
6271 {
6272 pack_fclose(f);
6273 return false;
6274 }
6275
6276 if(!read_deprecated_section_cversion(f))
6277 {
6278 pack_fclose(f);
6279 return false;
6280 }
6281
6282 if(s_version < 8)
6283 {
6284 subscreen_group g;
6285 memset(&g,0,sizeof(subscreen_group));
6286 if(read_one_old_subscreen(f,&g,s_version)!=0)
6287 {
6288 pack_fclose(f);
6289 return false;
6290 }
6291 if(g.ss_type != loadto.sub_type)
6292 {
6293 pack_fclose(f);
6294 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6295 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6296 return false;
6297 }
6298 loadto.clear();
6299 if(g.objects[0].type != ssoNULL)
6300 loadto.load_old(g);
6301 }
6302 else
6303 {
6304 ZCSubscreen tmp = ZCSubscreen();
6305 if (tmp.read(f, s_version))
6306 {
6307 pack_fclose(f);
6308 return false;
6309 }
6310 if(tmp.sub_type != loadto.sub_type)
6311 {
6312 pack_fclose(f);
6313 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6314 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6315 return false;
6316 }
6317 loadto.clear();
6318 loadto = tmp;
6319 }
6320
6321 pack_fclose(f);
6322 return true;
6323 }
6324
6325 bool setMapCount2(int32_t c)
6326 {
6327 int32_t oldmapcount=map_count;
6328 int32_t cur_map=Map.getCurrMap();
6329
6330 bound(c,1,MAXMAPS);
6331 map_count=c;
6332
6333 try
6334 {
6335 TheMaps.resize(c*MAPSCRS);
6336 Map.force_refr_pointer();
6337 map_autolayers.resize(c*6);
6338 }
6339 catch(...)
6340 {
6341 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6342 return false;
6343 }
6344
6345 bound(cur_map,0,c-1);
6346 if(map_count>oldmapcount)
6347 {
6348 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6349 {
6350 Map.setCurrMap(mc);
6351
6352 for(int32_t ms=0; ms<MAPSCRS; ms++)
6353 {
6354 Map.clearscr(ms);
6355 }
6356 }
6357 Map.setCurrMap(cur_map);
6358 }
6359 else
6360 {
6361 Map.setCurrMap(cur_map);
6362 if(!layers_valid(Map.CurrScr()))
6363 fix_layers(Map.CurrScr(), false);
6364
6365 for(int32_t i=0; i<MAXDMAPS; i++)
6366 {
6367 if(DMaps[i].map>=map_count)
6368 {
6369 DMaps[i].map=map_count-1;
6370 }
6371 }
6372 }
6373
6374 return true;
6375 }
6376
6377 extern BITMAP *bmap;
6378
6379 static bool loading_file_new = false;
6380 int32_t init_quest(std::string tileset_path)
6381 {
6382 if (tileset_path.empty())
6383 tileset_path = DEFAULT_TILESET;
6384
6385 loading_file_new = true;
6386 load_quest(tileset_path.c_str());
6387 loading_file_new = false;
6388
6389 set_window_title("ZC Editor - Untitled Quest");
6390 zinit.last_map = 0;
6391 zinit.last_screen = 0;
6392
6393 if(bmap != NULL)
6394 {
6395 destroy_bitmap(bmap);
6396 bmap=NULL;
6397 }
6398
6399 return 0;
6400 }
6401
6402 void set_questpwd(std::string_view pwd, bool use_keyfile)
6403 {
6404 header.use_keyfile=use_keyfile;
6405
6406 // string_view actually has some quirks that make it less than ideal here.
6407 // It'd probably be best to replace it, but this works for now.
6408 memset(header.password, 0, 256);
6409 strcpy(header.password, pwd.data());
6410 header.dirty_password=true;
6411
6412 cvs_MD5Context ctx;
6413 cvs_MD5Init(&ctx);
6414 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6415 cvs_MD5Final(header.pwd_hash, &ctx);
6416 }
6417
6418
6419 bool is_null_pwd_hash(uint8_t *pwd_hash)
6420 {
6421 cvs_MD5Context ctx;
6422 uint8_t md5sum[16];
6423 char pwd[2]="";
6424
6425 cvs_MD5Init(&ctx);
6426 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6427 cvs_MD5Final(md5sum, &ctx);
6428
6429 return (memcmp(md5sum,pwd_hash,16)==0);
6430 }
6431
6432 static DIALOG pwd_dlg[] =
6433 {
6434 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6435 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6436 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6437 // 2 (filename)
6438 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6439 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6440 // 4 (challenge hash)
6441 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6442 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6443 // 6 (password)
6444 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6445 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6446 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6447 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6448 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6449 };
6450
6451 int32_t reverse_string(char* str)
6452 {
6453
6454 if(NULL==str)
6455 {
6456 return -1; //no string
6457 }
6458
6459 int32_t l=(int32_t)strlen(str)-1; //get the string length
6460
6461 if(1==l)
6462 {
6463 return 1;
6464 }
6465
6466 char c;
6467
6468 for(int32_t x=0; x < l; x++,l--)
6469 {
6470 c = str[x];
6471 str[x] = str[l];
6472 str[l] = c;
6473 }
6474
6475 return 0;
6476 }
6477
6478 #ifdef __GNUC__
6479 #pragma GCC diagnostic push
6480 #pragma GCC diagnostic ignored "-Wunreachable-code"
6481 #endif
6482
6483 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6484 {
6485
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6486 11 return 1;
6487
6488 #ifdef __EMSCRIPTEN__
6489 return 1;
6490 #endif
6491
6492 //Protection against compiling a release version with password protection off.
6493 static bool passguard = false;
6494
6495 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6496 #define MUST_HAVE_PASSWORD
6497 passguard = true;
6498 #endif
6499
6500 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6501 #if (defined _MSC_VER || defined _NPASS)
6502 return 1;
6503 #endif
6504 #endif
6505 if(devpwd()) return 1;
6506
6507 char hash_string[33];
6508
6509 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6510 {
6511 return 1;
6512 }
6513
6514 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6515 return true;
6516
6517 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6518 pwd_dlg[2].dp=get_filename(filename);
6519 cvs_MD5Context ctx;
6520 uint8_t md5sum[16]={0};
6521 char response[33]="";
6522 char prompt[256]="";
6523
6524 memcpy(md5sum, hdr->pwd_hash, 16);
6525
6526 for(int32_t i=0; i<300; ++i)
6527 {
6528 for(int32_t j=0; j<16; ++j)
6529 {
6530 sprintf(response+j*2, "%02x", md5sum[j]);
6531 }
6532
6533 if(i&1)
6534 {
6535 reverse_string(response);
6536 }
6537
6538 if(i==149)
6539 {
6540 strcpy(hash_string, response);
6541 }
6542
6543 cvs_MD5Init(&ctx);
6544 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6545 cvs_MD5Final(md5sum, &ctx);
6546 }
6547
6548 pwd_dlg[4].dp=hash_string;
6549
6550 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6551 {
6552 sprintf(prompt,"%s",response);
6553 }
6554
6555 pwd_dlg[6].dp=prompt;
6556
6557 large_dialog(pwd_dlg);
6558
6559 int32_t cancel = do_zqdialog(pwd_dlg,6);
6560
6561 if(cancel == 8)
6562 return 2;
6563
6564 bool ret=check_questpwd(hdr, prompt);
6565
6566 if(!ret)
6567 {
6568 ret=(strcmp(response,prompt)==0);
6569 }
6570 return ret ? 1 : 0;
6571 11 }
6572
6573 void set_rules(byte* newrules);
6574 11 void popup_bugfix_dlg(const char* cfg)
6575 {
6576 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6577
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6578 {
6579
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6580
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6581 "\nWould you like to apply them?"
6582 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6583 11 [&](bool ret,bool dsa)
6584 {
6585 if(ret)
6586 {
6587 applyRuleTemplate(ruletemplateFixCompat);
6588 }
6589 if(dsa)
6590 {
6591 zc_set_config("zquest",cfg,1);
6592 }
6593 },
6594
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6595 0,false, //timeout - none
6596 true //"Don't show this again"
6597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6598 11 }
6599 11 }
6600
6601 #ifdef __GNUC__
6602 #pragma GCC diagnostic pop
6603 #endif
6604
6605 11 int32_t load_quest(const char *filename, bool show_progress)
6606 {
6607 char buf[2048];
6608 byte skip_flags[4];
6609
6610 11 dword tileset_flags = 0;
6611
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6612 {
6613 44 skip_flags[i]=0;
6614 44 }
6615
2/2
✓ Branch 0 taken 7623 times.
✓ Branch 1 taken 11 times.
7634 for(int32_t i=0; i<qr_MAX; i++)
6616 7623 set_qr(i,0);
6617 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6618
6619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6620 {
6621 init_quest(DEFAULT_TILESET);
6622 }
6623 else
6624 {
6625 11 int32_t accessret = quest_access(filename, &header);
6626
6627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6628 {
6629 init_quest(DEFAULT_TILESET);
6630
6631 if(accessret == 0)
6632 ret=qe_pwd;
6633 else
6634 ret=qe_cancel;
6635 }
6636 else
6637 {
6638 11 Map.clear();
6639 11 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6640 11 Map.setCurrScr(zinit.last_screen);
6641
6642
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filepath);
6643
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 Map.setViewSize(zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1));
6644
6645 extern int32_t current_mappage;
6646 11 current_mappage = 0;
6647 11 bool found_default = false;
6648
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6649 {
6650 83 auto &pg = map_page[q];
6651
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6652 {
6653 2 current_mappage = q;
6654 2 break;
6655 }
6656
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6657 72 continue;
6658 else
6659 {
6660 9 current_mappage = q;
6661 9 found_default = true;
6662 }
6663 9 }
6664
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6665
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6666
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6667 11 saved = true;
6668
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6669
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule");
6670
6671
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6672 {
6673 destroy_bitmap(bmap);
6674 bmap=NULL;
6675 }
6676
6677
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6678 {
6679 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6680 set_window_title(buf);
6681 }
6682 11 }
6683 }
6684
6685 11 Map.ClearCommandHistory();
6686
6687
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6688 {
6689 void load_size_poses();
6690 load_size_poses();
6691 }
6692
6693 11 return ret;
6694 }
6695
6696 int32_t load_tileset(const char *filename, dword tsetflags)
6697 {
6698 byte skip_flags[4];
6699
6700 for(int32_t i=0; i<4; ++i)
6701 skip_flags[i]=0;
6702 for(int32_t i=0; i<qr_MAX; i++)
6703 set_qr(i,0);
6704 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6705
6706 if(ret!=qe_OK)
6707 init_quest(DEFAULT_TILESET);
6708 else
6709 {
6710 if(tsetflags & TILESET_BUGFIX)
6711 applyRuleTemplate(ruletemplateFixCompat);
6712
6713 int32_t accessret = quest_access(filename, &header);
6714
6715 if(accessret != 1)
6716 {
6717 init_quest(DEFAULT_TILESET);
6718
6719 if(accessret == 0)
6720 ret=qe_pwd;
6721 else
6722 ret=qe_cancel;
6723 }
6724 else
6725 {
6726 Map.clear();
6727 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6728 Map.setCurrScr(zinit.last_screen);
6729 extern int32_t current_mappage;
6730 current_mappage = 0;
6731 bool found_default = false;
6732 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6733 {
6734 auto &pg = map_page[q];
6735 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6736 {
6737 current_mappage = q;
6738 break;
6739 }
6740 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6741 continue;
6742 else
6743 {
6744 current_mappage = q;
6745 found_default = true;
6746 }
6747 }
6748 refresh(rALL);
6749 refresh_pal();
6750 set_rules(quest_rules);
6751
6752 if(bmap != NULL)
6753 {
6754 destroy_bitmap(bmap);
6755 bmap=NULL;
6756 }
6757
6758 set_window_title("ZC Editor - Untitled Quest");
6759 first_save = saved = false;
6760 memset(filepath,0,255);
6761 memset(temppath,0,255);
6762 }
6763 }
6764
6765 Map.ClearCommandHistory();
6766
6767 return ret;
6768 }
6769
6770 130 bool write_midi(MIDI *m,PACKFILE *f)
6771 {
6772 int32_t c;
6773
6774
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6775
6776
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6777 {
6778
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6779
6780
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6781 {
6782
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6783 return false;
6784 1264 }
6785 4160 }
6786
6787 130 return true;
6788 130 }
6789
6790 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6791 {
6792 9 dword section_id=ID_HEADER;
6793 9 dword section_version=V_HEADER;
6794 9 dword section_size=0;
6795
6796 //file header string
6797
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6798 {
6799 new_return(1);
6800 }
6801
6802 //section id
6803
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6804 {
6805 new_return(2);
6806 }
6807
6808 //section version info
6809
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6810 {
6811 new_return(3);
6812 }
6813
6814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6815 {
6816 new_return(4);
6817 }
6818
6819
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6820 {
6821 18 fake_pack_writing=(writecycle==0);
6822
6823 //section size
6824
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6825 {
6826 new_return(5);
6827 }
6828
6829 18 writesize=0;
6830
6831 //finally... section data
6832
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6833 {
6834 new_return(6);
6835 }
6836
6837
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6838 {
6839 new_return(7);
6840 }
6841
6842
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6843 {
6844 new_return(8);
6845 }
6846
6847
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6848 {
6849 new_return(10);
6850 }
6851
6852
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6853 {
6854 new_return(11);
6855 }
6856
6857
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6858 {
6859 new_return(12);
6860 }
6861
6862
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6863 {
6864 new_return(13);
6865 }
6866
6867
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6868 {
6869 new_return(14);
6870 }
6871
6872
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6873 {
6874 new_return(15);
6875 }
6876
6877
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6878 {
6879 new_return(16);
6880 }
6881
6882
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6883 {
6884 new_return(17);
6885 }
6886
6887
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6888 {
6889 new_return(19);
6890 }
6891
6892
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6893 //this is for map count, it seems. -Z
6894 {
6895 new_return(20);
6896 }
6897
6898 18 auto version = getVersion();
6899
6900
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6901 {
6902 new_return(21);
6903 }
6904
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6905 {
6906 new_return(22);
6907 }
6908
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6909 {
6910 new_return(23);
6911 }
6912 // Fourth component is deprecated.
6913
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6914 {
6915 new_return(24);
6916 }
6917
6918 // Numerous prerelease stages is deprecated.
6919
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6920 {
6921 new_return(25);
6922 }
6923
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6924 {
6925 new_return(26);
6926 }
6927
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6928 {
6929 new_return(27);
6930 }
6931
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6932 {
6933 new_return(28);
6934 }
6935
6936
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6937 {
6938 new_return(29);
6939 }
6940
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6941 {
6942 new_return(30);
6943 }
6944
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6945 {
6946 new_return(31);
6947 }
6948
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6949 {
6950 new_return(32);
6951 }
6952
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6953 {
6954 new_return(33);
6955 }
6956
6957 // This is no longer set to anything.
6958 const char* tempsig[256];
6959 18 memset(tempsig, 0, 256);
6960
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6961 {
6962 new_return(34);
6963 }
6964
6965 char tempcompilersig[256];
6966 18 memset(tempcompilersig, 0, 256);
6967 18 strcpy(tempcompilersig, COMPILER_NAME);
6968
6969
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6970 {
6971 new_return(35);
6972 }
6973
6974 char tempcompilerversion[256];
6975 18 memset(tempcompilerversion, 0, 256);
6976 #ifdef _MSC_VER
6977 zc_itoa(_MSC_VER,tempcompilerversion,10);
6978 #else
6979 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6980 #endif
6981
6982
6983
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
6984 {
6985 new_return(36);
6986 }
6987
6988
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
6989 {
6990 new_return(37);
6991 }
6992
6993 // V_ZC_COMPILERSIG - a deprecated version field.
6994
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
6995 {
6996 new_return(38);
6997 }
6998 #ifdef _MSC_VER
6999 if(!p_iputl((_MSC_VER / 100),f))
7000 {
7001 new_return(39);
7002 }
7003 #else
7004
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7005 {
7006 new_return(39);
7007 }
7008 #endif
7009
7010
7011
7012 #ifdef _MSC_VER
7013 if(!p_iputl((_MSC_VER % 100),f))
7014 {
7015 new_return(41);
7016 }
7017 #else
7018
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7019 {
7020 new_return(41);
7021 }
7022 #endif
7023
7024 #ifdef _MSC_VER
7025 # if _MSC_VER >= 1400
7026 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7027 {
7028 new_return(40);
7029 }
7030 # else
7031 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7032 {
7033 new_return(40);
7034 }
7035 #endif
7036 #else
7037
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7038 {
7039 new_return(40);
7040 }
7041 #endif
7042
7043 #ifdef _MSC_VER
7044 if(!p_iputl((_MSC_BUILD),f))
7045 {
7046 new_return(42);
7047 }
7048 #else
7049
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7050 {
7051 new_return(42);
7052 }
7053 #endif
7054
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7055 {
7056 new_return(43);
7057 }
7058
7059 // Modules were removed (replaced by zinfo).
7060 char tempmodulename[1024];
7061 18 memset(tempmodulename, 0, 1024);
7062
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7063 {
7064 new_return(44);
7065 }
7066
7067 char tempdate[256];
7068 18 memset(tempdate, 0, 256);
7069 18 strcpy(tempdate, __DATE__);
7070
7071
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7072 {
7073 new_return(45);
7074 }
7075 char temptime[256];
7076 18 memset(temptime, 0, 256);
7077 18 strcpy(temptime, __TIME__);
7078
7079
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7080 {
7081 new_return(46);
7082 }
7083
7084
7085 char temptimezone[6];
7086 18 memset(temptimezone, 0, 6);
7087 18 strcpy(temptimezone, __TIMEZONE__);
7088
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7089 {
7090 new_return(47);
7091 }
7092
7093
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7094 {
7095 new_return(48);
7096 }
7097
7098
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7099 {
7100 new_return(49);
7101 }
7102
7103
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7104 {
7105 new_return(50);
7106 }
7107
7108
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7109 {
7110 9 section_size=writesize;
7111 9 }
7112 18 }
7113
7114
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7115 {
7116 char ebuf[80];
7117 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7118 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7119 }
7120
7121 9 new_return(0);
7122 }
7123
7124 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7125 {
7126 //these are here to bypass compiler warnings about unused arguments
7127 9 Header=Header;
7128
7129 9 dword section_id=ID_RULES;
7130 9 dword section_version=V_RULES;
7131 9 dword section_size=0;
7132
7133 //section id
7134
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7135 {
7136 new_return(1);
7137 }
7138
7139 //section version info
7140
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7141 {
7142 new_return(2);
7143 }
7144
7145
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7146 {
7147 new_return(3);
7148 }
7149
7150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7151 {
7152 new_return(6);
7153 }
7154
7155
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7156 {
7157 18 fake_pack_writing=(writecycle==0);
7158
7159 //section size
7160
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7161 {
7162 new_return(4);
7163 }
7164
7165 18 writesize=0;
7166
7167 //finally... section data
7168
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7169 {
7170 new_return(5);
7171 }
7172
7173
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7174 {
7175 9 section_size=writesize;
7176 9 }
7177 18 }
7178
7179
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7180 {
7181 char ebuf[80];
7182 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7183 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7184 }
7185
7186 9 new_return(0);
7187 }
7188
7189
7190 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7191 {
7192 //these are here to bypass compiler warnings about unused arguments
7193 9 Header=Header;
7194
7195 9 dword section_id=ID_DOORS;
7196 9 dword section_version=V_DOORS;
7197 9 dword section_size=0;
7198
7199 //section id
7200
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7201 {
7202 new_return(1);
7203 }
7204
7205 //section version info
7206
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7207 {
7208 new_return(2);
7209 }
7210
7211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7212 {
7213 new_return(3);
7214 }
7215
7216
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7217 {
7218 18 fake_pack_writing=(writecycle==0);
7219
7220 //section size
7221
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7222 {
7223 new_return(4);
7224 }
7225
7226 18 writesize=0;
7227
7228 //finally... section data
7229
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7230 {
7231 new_return(5);
7232 }
7233
7234
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7235 {
7236 //name
7237 char name[21];
7238 320 memset(name, 21, (char)0);
7239 320 strcpy(name, DoorComboSetNames[i].c_str());
7240
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7241 {
7242 new_return(6);
7243 }
7244
7245 //up door
7246
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7247 {
7248
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7249 {
7250
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7251 {
7252 new_return(7);
7253 }
7254 11520 }
7255 2880 }
7256
7257
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7258 {
7259
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7260 {
7261
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7262 {
7263 new_return(8);
7264 }
7265 11520 }
7266 2880 }
7267
7268 //down door
7269
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7270 {
7271
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7272 {
7273
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7274 {
7275 new_return(9);
7276 }
7277 11520 }
7278 2880 }
7279
7280
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7281 {
7282
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7283 {
7284
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7285 {
7286 new_return(10);
7287 }
7288 11520 }
7289 2880 }
7290
7291
7292 //left door
7293
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7294 {
7295
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7296 {
7297
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7298
7299 {
7300 new_return(11);
7301 }
7302 17280 }
7303 2880 }
7304
7305
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7306 {
7307
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7308 {
7309
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7310 {
7311 new_return(12);
7312 }
7313 17280 }
7314 2880 }
7315
7316 //right door
7317
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7318 {
7319
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7320 {
7321
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7322 {
7323 new_return(13);
7324 }
7325 17280 }
7326 2880 }
7327
7328
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7329 {
7330
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7331 {
7332
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7333 {
7334 new_return(14);
7335 }
7336 17280 }
7337 2880 }
7338
7339
7340 //up bomb rubble
7341
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7342 {
7343
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7344 {
7345 new_return(15);
7346 }
7347 640 }
7348
7349
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7350 {
7351
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7352 {
7353 new_return(16);
7354 }
7355 640 }
7356
7357 //down bomb rubble
7358
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7359 {
7360
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7361 {
7362 new_return(17);
7363 }
7364 640 }
7365
7366
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7367 {
7368
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7369 {
7370 new_return(18);
7371 }
7372 640 }
7373
7374 //left bomb rubble
7375
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7376 {
7377
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7378 {
7379 new_return(19);
7380 }
7381 960 }
7382
7383
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7384 {
7385
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7386 {
7387 new_return(20);
7388 }
7389 960 }
7390
7391 //right bomb rubble
7392
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7393 {
7394
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7395 {
7396 new_return(21);
7397 }
7398 960 }
7399
7400
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7401 {
7402
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7403 {
7404 new_return(22);
7405 }
7406 960 }
7407
7408 //walkthrough stuff
7409
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7410 {
7411
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7412 {
7413 new_return(23);
7414 }
7415 1280 }
7416
7417
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7418 {
7419
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7420 {
7421 new_return(24);
7422 }
7423 1280 }
7424
7425 //flags
7426
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7427 {
7428
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7429 {
7430 new_return(25);
7431 }
7432 640 }
7433 320 }
7434
7435
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7436 {
7437 9 section_size=writesize;
7438 9 }
7439 18 }
7440
7441
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7442 {
7443 char ebuf[80];
7444 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7445 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7446 }
7447
7448 9 new_return(0);
7449 }
7450
7451 9 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7452 {
7453 //these are here to bypass compiler warnings about unused arguments
7454 9 version=version;
7455 9 build=build;
7456
7457 9 word dmap_count=count_dmaps();
7458 9 dword section_id=ID_DMAPS;
7459 9 dword section_version=V_DMAPS;
7460 9 dword section_size=0;
7461
7462 //section id
7463
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7464 {
7465 new_return(1);
7466 }
7467
7468 //section version info
7469
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7470 {
7471 new_return(2);
7472 }
7473
7474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7475 {
7476 new_return(3);
7477 }
7478
7479
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7480 {
7481 18 fake_pack_writing=(writecycle==0);
7482
7483 //section size
7484
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7485 {
7486 new_return(4);
7487 }
7488
7489 18 writesize=0;
7490
7491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7493
7494 //finally... section data
7495
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7496 {
7497 new_return(5);
7498 }
7499
7500
7501
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7502 {
7503 9216 DMaps[i].validate_subscreens();
7504
7505
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].map,f))
7506 {
7507 new_return(6);
7508 }
7509
7510
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].level,f))
7511 {
7512 new_return(7);
7513 }
7514
7515
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].xoff,f))
7516 {
7517 new_return(8);
7518 }
7519
7520
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].compass,f))
7521 {
7522 new_return(9);
7523 }
7524
7525
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].color,f))
7526 {
7527 new_return(10);
7528 }
7529
7530
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].midi,f))
7531 {
7532 new_return(11);
7533 }
7534
7535
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].cont,f))
7536 {
7537 new_return(12);
7538 }
7539
7540
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].type,f))
7541 {
7542 new_return(13);
7543 }
7544
7545
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7546 {
7547
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[i].grid[j],f))
7548 {
7549 new_return(14);
7550 }
7551 73728 }
7552
7553
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7554 {
7555 new_return(15);
7556 }
7557
7558
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[i].title,f))
7559 {
7560 new_return(16);
7561 }
7562
7563
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7564 {
7565 new_return(17);
7566 }
7567
7568
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_1_tile,f))
7569 {
7570 new_return(18);
7571 }
7572
7573
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_1_cset,f))
7574 {
7575 new_return(19);
7576 }
7577
7578
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_2_tile,f))
7579 {
7580 new_return(20);
7581 }
7582
7583
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_2_cset,f))
7584 {
7585 new_return(21);
7586 }
7587
7588
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_1_tile,f))
7589 {
7590 new_return(22);
7591 }
7592
7593
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_1_cset,f))
7594 {
7595 new_return(23);
7596 }
7597
7598
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_2_tile,f))
7599 {
7600 new_return(24);
7601 }
7602
7603
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_2_cset,f))
7604 {
7605 new_return(25);
7606 }
7607
7608
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7609 {
7610 new_return(26);
7611 }
7612
7613
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].tmusictrack,f))
7614 {
7615 new_return(25);
7616 }
7617
7618
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].active_subscreen,f))
7619 {
7620 new_return(26);
7621 }
7622
7623
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].passive_subscreen,f))
7624 {
7625 new_return(27);
7626 }
7627
7628 byte disabled[32];
7629 9216 memset(disabled,0,32);
7630
7631
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7632 {
7633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2359296 times.
2359296 if(DMaps[i].disableditems[j])
7634 {
7635 disabled[j/8] |= (1 << (j%8));
7636 }
7637 2359296 }
7638
7639
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7640 {
7641 new_return(28);
7642 }
7643
7644
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].flags,f))
7645 {
7646 new_return(29);
7647 }
7648
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].sideview,f))
7649 {
7650 new_return(30);
7651 }
7652
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].script,f))
7653 {
7654 new_return(31);
7655 }
7656
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7657 {
7658
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].initD[q],f))
7659 {
7660 new_return(32);
7661 }
7662
7663 73728 }
7664
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7665 {
7666
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7667 {
7668
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[i].initD_label[q][w],f))
7669 {
7670 new_return(33);
7671 }
7672 4792320 }
7673 73728 }
7674
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].active_sub_script,f))
7675 {
7676 new_return(34);
7677 }
7678
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].passive_sub_script,f))
7679 {
7680 new_return(35);
7681 }
7682
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7683 {
7684
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].sub_initD[q],f))
7685 {
7686 new_return(36);
7687 }
7688 73728 }
7689
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7690 {
7691
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7692 {
7693
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7694 {
7695 new_return(37);
7696 }
7697 4792320 }
7698 73728 }
7699
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].onmap_script,f))
7700 {
7701 new_return(38);
7702 }
7703
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7704 {
7705
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7706 {
7707 new_return(39);
7708 }
7709 73728 }
7710
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7711 {
7712
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7713 {
7714
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7715 {
7716 new_return(40);
7717 }
7718 4792320 }
7719 73728 }
7720
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].mirrorDMap,f))
7721 {
7722 new_return(41);
7723 }
7724
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7725 {
7726 new_return(42);
7727 }
7728
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7729 {
7730 new_return(43);
7731 }
7732
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7733 {
7734 new_return(44);
7735 }
7736
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7737 {
7738 new_return(45);
7739 }
7740
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].overlay_subscreen, f))
7741 new_return(46);
7742
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].intro_string_id, f))
7743 new_return(47);
7744 9216 }
7745
7746
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7747 {
7748 9 section_size=writesize;
7749 9 }
7750 18 }
7751
7752
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7753 {
7754 char ebuf[80];
7755 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7756 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7757 }
7758
7759 9 new_return(0);
7760 }
7761
7762 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7763 {
7764 //these are here to bypass compiler warnings about unused arguments
7765 9 Header=Header;
7766
7767 9 dword section_id=ID_COLORS;
7768 9 dword section_version=V_COLORS;
7769 9 dword section_size = 0;
7770
7771 //section id
7772
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7773 {
7774 new_return(1);
7775 }
7776
7777
7778 //section version info
7779
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7780 {
7781 new_return(2);
7782 }
7783
7784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7785 {
7786 new_return(3);
7787 }
7788
7789
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7790 {
7791 18 fake_pack_writing=(writecycle==0);
7792
7793 //section size
7794
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7795 {
7796 new_return(4);
7797 }
7798
7799 18 writesize=0;
7800
7801
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7802 {
7803 new_return(5);
7804 }
7805
7806
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7807 {
7808 new_return(6);
7809 }
7810
7811
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7812 {
7813 new_return(7);
7814 }
7815
7816
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7817 {
7818 new_return(8);
7819 }
7820
7821
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7822 {
7823 new_return(9);
7824 }
7825
7826
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7827 {
7828 new_return(10);
7829 }
7830
7831
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7832 {
7833 new_return(11);
7834 }
7835
7836
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7837 {
7838 new_return(12);
7839 }
7840
7841
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7842 {
7843 new_return(13);
7844 }
7845
7846
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7847 {
7848 new_return(14);
7849 }
7850
7851
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7852 {
7853 new_return(15);
7854 }
7855
7856
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7857 {
7858 new_return(16);
7859 }
7860
7861
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7862 {
7863 new_return(17);
7864 }
7865
7866
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7867 {
7868 new_return(18);
7869 }
7870
7871
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7872 {
7873 new_return(19);
7874 }
7875
7876
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7877 {
7878 new_return(20);
7879 }
7880
7881
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7882 {
7883 new_return(21);
7884 }
7885
7886
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7887 {
7888 new_return(22);
7889 }
7890
7891
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7892 {
7893 new_return(23);
7894 }
7895
7896
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7897 {
7898 new_return(24);
7899 }
7900
7901
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7902 {
7903 new_return(31);
7904 }
7905
7906
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7907 {
7908 new_return(32);
7909 }
7910
7911
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7912 {
7913 new_return(33);
7914 }
7915
7916
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7917 {
7918 new_return(34);
7919 }
7920
7921
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7922 {
7923 new_return(35);
7924 }
7925
7926
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7927 {
7928 new_return(36);
7929 }
7930
7931
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7932 {
7933 new_return(37);
7934 }
7935
7936
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7937 {
7938 new_return(38);
7939 }
7940
7941
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7942 {
7943 new_return(39);
7944 }
7945
7946
7947
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7948 {
7949 9 section_size=writesize;
7950 9 }
7951 18 }
7952
7953
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7954 {
7955 char ebuf[80];
7956 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7957 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7958 }
7959
7960 9 new_return(0);
7961 }
7962
7963 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7964 {
7965 //these are here to bypass compiler warnings about unused arguments
7966 9 Header=Header;
7967
7968 9 dword section_id=ID_ICONS;
7969 9 dword section_version=V_ICONS;
7970 9 dword section_size = 0;
7971
7972 //section id
7973
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7974 {
7975 new_return(1);
7976 }
7977
7978 //section version info
7979
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7980 {
7981 new_return(2);
7982 }
7983
7984
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7985 {
7986 new_return(3);
7987 }
7988
7989
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7990 {
7991 18 fake_pack_writing=(writecycle==0);
7992
7993 //section size
7994
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7995 {
7996 new_return(4);
7997 }
7998
7999 18 writesize=0;
8000
8001
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
8002 {
8003
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
8004 {
8005 new_return(5);
8006 }
8007 72 }
8008
8009
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8010 {
8011 9 section_size=writesize;
8012 9 }
8013 18 }
8014
8015
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8016 {
8017 char ebuf[80];
8018 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8019 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8020 }
8021
8022 9 new_return(0);
8023 }
8024
8025 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8026 {
8027 //these are here to bypass compiler warnings about unused arguments
8028 9 Header=Header;
8029
8030 9 dword section_id=ID_MISC;
8031 9 dword section_version=V_MISC;
8032 9 word shops=count_shops(&QMisc);
8033 9 word infos=count_infos(&QMisc);
8034 9 word warprings=count_warprings(&QMisc);
8035 9 word triforces=8;
8036 9 dword section_size = 0;
8037
8038 //section id
8039
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8040 {
8041 new_return(1);
8042 }
8043
8044
8045 //section version info
8046
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8047 {
8048 new_return(2);
8049 }
8050
8051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8052 {
8053 new_return(3);
8054 }
8055
8056
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8057 {
8058 18 fake_pack_writing=(writecycle==0);
8059
8060 //section size
8061
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8062 {
8063 new_return(4);
8064 }
8065
8066 18 writesize=0;
8067
8068 //shops
8069
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8070 {
8071 new_return(5);
8072 }
8073
8074
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8075 {
8076
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8077 {
8078 new_return(6);
8079 }
8080
8081
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8082 {
8083
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8084 {
8085 new_return(7);
8086 }
8087 480 }
8088
8089
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8090 {
8091
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8092 {
8093 new_return(8);
8094 }
8095 480 }
8096
8097
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8098 {
8099
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8100 {
8101 new_return(9);
8102 }
8103 480 }
8104 160 }
8105
8106 //infos
8107
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8108 {
8109 new_return(10);
8110 }
8111
8112
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8113 {
8114
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8115 {
8116 new_return(11);
8117 }
8118
8119
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8120 {
8121
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8122 {
8123 new_return(12);
8124 }
8125 480 }
8126
8127
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8128 {
8129
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8130 {
8131 new_return(13);
8132 }
8133 480 }
8134 160 }
8135
8136 //warp rings
8137
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8138 {
8139 new_return(14);
8140 }
8141
8142
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8143 {
8144
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8145 {
8146
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8147 {
8148 new_return(15);
8149 }
8150 1872 }
8151
8152
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8153 {
8154
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8155 {
8156 new_return(16);
8157 }
8158 1872 }
8159
8160
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8161 {
8162 new_return(17);
8163 }
8164 208 }
8165
8166 //triforce pieces
8167
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8168 {
8169
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8170 {
8171 new_return(18);
8172 }
8173 144 }
8174
8175 //end string
8176
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8177 {
8178 new_return(19);
8179 }
8180
8181 //V_MISC >= 8
8182
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8183 {
8184
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8185 {
8186
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8187 {
8188 new_return(20);
8189 }
8190 480 }
8191 160 }
8192 //V_MISC >= 9
8193
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8194 {
8195
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8196 new_return(21);
8197 576 }
8198
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8199 {
8200
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8201
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8202 new_return(22);
8203 576 }
8204 //V_MISC >= 11
8205
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8206 new_return(23);
8207
8208 //V_MISC >= 12
8209
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8210 {
8211
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8212 new_return(24);
8213 4608 }
8214
8215 //V_MISC >= 13
8216
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8217 {
8218 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8219
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8220 new_return(25);
8221
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8222 {
8223
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8224 new_return(25);
8225
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8226 new_return(25);
8227 3456 }
8228
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8229 new_return(25);
8230
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8231 new_return(25);
8232 1152 }
8233
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8234 {
8235 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8236
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8237 new_return(26);
8238
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8239 {
8240
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8241 new_return(26);
8242
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8243 new_return(26);
8244
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8245 new_return(26);
8246
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8247 new_return(26);
8248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8249 new_return(26);
8250 13824 }
8251 4608 }
8252
8253 //V_MISC >= 14
8254
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8255 {
8256
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8257 new_return(27);
8258 4608 }
8259
8260
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8261 {
8262 9 section_size=writesize;
8263 9 }
8264 18 }
8265
8266
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8267 {
8268 char ebuf[80];
8269 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8270 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8271 }
8272
8273 9 new_return(0);
8274 }
8275
8276 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8277 {
8278 //these are here to bypass compiler warnings about unused arguments
8279 9 Header=Header;
8280
8281 9 dword section_id=ID_ITEMS;
8282 9 dword section_version=V_ITEMS;
8283 // dword section_size=0;
8284 9 dword section_size = 0;
8285
8286 //section id
8287
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8288 {
8289 new_return(1);
8290 }
8291
8292 //section version info
8293
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8294 {
8295 new_return(2);
8296 }
8297
8298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8299 {
8300 new_return(3);
8301 }
8302
8303
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8304 {
8305 18 fake_pack_writing=(writecycle==0);
8306
8307 //section size
8308
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8309 {
8310 new_return(4);
8311 }
8312
8313 18 writesize=0;
8314
8315 //finally... section data
8316
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8317 {
8318 new_return(5);
8319 }
8320
8321
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8322 {
8323
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8324 {
8325 new_return(5);
8326 }
8327 4608 }
8328
8329
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8330 {
8331
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8332 {
8333 new_return(6);
8334 }
8335
8336
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8337 {
8338 new_return(7);
8339 }
8340
8341
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8342 {
8343 new_return(8);
8344 }
8345
8346
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8347 {
8348 new_return(9);
8349 }
8350
8351
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8352 {
8353 new_return(10);
8354 }
8355
8356
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8357 {
8358 new_return(11);
8359 }
8360
8361
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8362 {
8363 new_return(12);
8364 }
8365
8366
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].family,f))
8367 {
8368 new_return(13);
8369 }
8370
8371
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].fam_type,f))
8372 {
8373 new_return(14);
8374 }
8375
8376
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8377 {
8378 new_return(14);
8379 }
8380
8381
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8382 {
8383 new_return(15);
8384 }
8385
8386
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8387 {
8388 new_return(16);
8389 }
8390
8391
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8392 {
8393 new_return(17);
8394 }
8395
8396
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8397 {
8398 new_return(18);
8399 }
8400
8401
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8402 {
8403 new_return(19);
8404 }
8405
8406
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8407 {
8408 new_return(21);
8409 }
8410
8411
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8412 {
8413 new_return(22);
8414 }
8415
8416
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8417 {
8418 new_return(23);
8419 }
8420
8421
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8422 {
8423
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8424 {
8425 new_return(24);
8426 }
8427 36864 }
8428
8429
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8430 {
8431
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8432 {
8433 new_return(25);
8434 }
8435 9216 }
8436
8437
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8438 {
8439 new_return(26);
8440 }
8441
8442
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8443 {
8444 new_return(27);
8445 }
8446
8447
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8448 {
8449 new_return(28);
8450 }
8451
8452
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8453 {
8454 new_return(29);
8455 }
8456
8457
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8458 {
8459 new_return(30);
8460 }
8461
8462
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8463 {
8464 new_return(31);
8465 }
8466
8467
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8468 {
8469 new_return(32);
8470 }
8471
8472
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8473 {
8474 new_return(33);
8475 }
8476
8477
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8478 {
8479 new_return(34);
8480 }
8481
8482
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8483 {
8484 new_return(35);
8485 }
8486
8487
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8488 {
8489 new_return(36);
8490 }
8491
8492
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8493 {
8494 new_return(37);
8495 }
8496
8497
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8498 {
8499 new_return(38);
8500 }
8501
8502
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8503 {
8504
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8505 {
8506 new_return(39);
8507 }
8508 9216 }
8509
8510
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8511 {
8512 new_return(40);
8513 }
8514
8515
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8516 {
8517 new_return(41);
8518 }
8519
8520
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8521 {
8522 new_return(42);
8523 }
8524
8525
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8526 {
8527 new_return(43);
8528 }
8529
8530
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8531 {
8532 new_return(44);
8533 }
8534
8535
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8536 {
8537 new_return(45);
8538 }
8539
8540
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8541 {
8542 new_return(46);
8543 }
8544
8545
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8546 {
8547 new_return(47);
8548 }
8549
8550
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8551 {
8552 new_return(48);
8553 }
8554
8555
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8556 {
8557 new_return(48);
8558 }
8559
8560 //New itemdata vars -Z
8561 //! version 27
8562
8563
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].useweapon,f))
8564 {
8565 new_return(49);
8566 }
8567
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usedefence,f))
8568 {
8569 new_return(50);
8570 }
8571
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8572 {
8573 new_return(51);
8574 }
8575
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8576 {
8577 new_return(52);
8578 }
8579
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8580
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8581 {
8582 new_return(53);
8583 }
8584 46080 }
8585 //version 28
8586
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8587 {
8588 new_return(54);
8589 }
8590
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < INITIAL_D; q++ )
8591 {
8592
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].weap_initiald[q],f))
8593 {
8594 new_return(55);
8595 }
8596 36864 }
8597
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8598 {
8599
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8600 {
8601 new_return(56);
8602 }
8603 9216 }
8604
8605
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8606 {
8607 new_return(57);
8608 }
8609
8610
8611
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8612 {
8613 new_return(58);
8614 }
8615
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8616 {
8617 new_return(59);
8618 }
8619
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8620 {
8621 new_return(60);
8622 }
8623
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8624 {
8625 new_return(61);
8626 }
8627
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8628 {
8629 new_return(62);
8630 }
8631
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8632 {
8633 new_return(63);
8634 }
8635
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8636 {
8637 new_return(64);
8638 }
8639
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hxofs,f))
8640 {
8641 new_return(65);
8642 }
8643
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hyofs,f))
8644 {
8645 new_return(66);
8646 }
8647
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hxsz,f))
8648 {
8649 new_return(67);
8650 }
8651
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hysz,f))
8652 {
8653 new_return(68);
8654 }
8655
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_hzsz,f))
8656 {
8657 new_return(69);
8658 }
8659
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_xofs,f))
8660 {
8661 new_return(70);
8662 }
8663
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_yofs,f))
8664 {
8665 new_return(71);
8666 }
8667
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].weaponscript,f))
8668 {
8669 new_return(72);
8670 }
8671
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8672 {
8673 new_return(73);
8674 }
8675
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8676 {
8677
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8678 {
8679 new_return(74);
8680 }
8681 9216 }
8682
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8683 {
8684 new_return(75);
8685 }
8686
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8687 {
8688 new_return(76);
8689 }
8690
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8691 {
8692 new_return(77);
8693 }
8694
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapoverrideFLAGS,f))
8695 {
8696 new_return(78);
8697 }
8698
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_tilew,f))
8699 {
8700 new_return(79);
8701 }
8702
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weap_tileh,f))
8703 {
8704 new_return(80);
8705 }
8706
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8707 {
8708 new_return(81);
8709 }
8710
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8711 {
8712 new_return(82);
8713 }
8714
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8715 {
8716 new_return(83);
8717 }
8718
8719
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8720 {
8721
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8722 {
8723 new_return(84);
8724 }
8725 9216 }
8726
8727 //InitD[] labels
8728
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8729 {
8730
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8731 {
8732
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8733 {
8734 new_return(85);
8735 }
8736 2396160 }
8737
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8738 {
8739
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].weapon_initD_label[q][w],f))
8740 {
8741 new_return(86);
8742 }
8743 2396160 }
8744
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8745 {
8746
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8747 {
8748 new_return(87);
8749 }
8750 2396160 }
8751
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8752 {
8753 new_return(88);
8754 }
8755 36864 }
8756
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8757 {
8758
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8759 {
8760 new_return(89);
8761 }
8762
8763 9216 }
8764
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8765 {
8766 new_return(90);
8767 }
8768
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8769 {
8770 new_return(91);
8771 }
8772
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 std::string dispname(itemsbuf[i].display_name);
8773
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_putcstr(dispname,f))
8774 new_return(92);
8775
2/2
✓ Branch 0 taken 23040 times.
✓ Branch 1 taken 4608 times.
27648 for(int q = 0; q < WPNSPR_MAX; ++q)
8776 {
8777
2/4
✓ Branch 0 taken 23040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23040 times.
✗ Branch 3 not taken.
23040 if(!p_putc(itemsbuf[i].burnsprs[q], f))
8778 new_return(93);
8779
2/4
✓ Branch 0 taken 23040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23040 times.
✗ Branch 3 not taken.
23040 if(!p_putc(itemsbuf[i].light_rads[q], f))
8780 new_return(94);
8781 23040 }
8782 4608 }
8783
8784
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8785 {
8786 9 section_size=writesize;
8787 9 }
8788 18 }
8789
8790
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8791 {
8792 char ebuf[80];
8793 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8794 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8795 }
8796
8797 9 new_return(0);
8798 }
8799
8800 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8801 {
8802 //these are here to bypass compiler warnings about unused arguments
8803 9 Header=Header;
8804
8805 9 dword section_id=ID_WEAPONS;
8806 9 dword section_version=V_WEAPONS;
8807 9 dword section_size = 0;
8808
8809 //section id
8810
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8811 {
8812 new_return(1);
8813 }
8814
8815 //section version info
8816
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8817 {
8818 new_return(2);
8819 }
8820
8821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8822 {
8823 new_return(3);
8824 }
8825
8826
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8827 {
8828 18 fake_pack_writing=(writecycle==0);
8829
8830 //section size
8831
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8832 {
8833 new_return(4);
8834 }
8835
8836 18 writesize=0;
8837
8838 //finally... section data
8839
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8840 {
8841 new_return(5);
8842 }
8843
8844
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8845 {
8846
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8847 {
8848 new_return(5);
8849 }
8850 4608 }
8851
8852
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8853 {
8854
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8855 {
8856 new_return(7);
8857 }
8858
8859
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8860 {
8861 new_return(8);
8862 }
8863
8864
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8865 {
8866 new_return(9);
8867 }
8868
8869
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8870 {
8871 new_return(10);
8872 }
8873
8874
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8875 {
8876 new_return(11);
8877 }
8878
8879
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8880 {
8881 new_return(12);
8882 }
8883
8884
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8885 {
8886 new_return(12);
8887 }
8888 4608 }
8889
8890
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8891 {
8892 9 section_size=writesize;
8893 9 }
8894 18 }
8895
8896
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8897 {
8898 char ebuf[80];
8899 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8900 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8901 }
8902
8903 9 new_return(0);
8904 }
8905
8906 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8907 {
8908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8909 return qe_invalid;
8910
8911 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8912 12784 bool is_0x80_screen = j >= 0x80;
8913
8914
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8915 return qe_invalid;
8916
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8917 4404 return qe_OK;
8918 //Calculate what needs writing
8919 8380 uint32_t scr_has_flags = 0;
8920
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8921
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8922 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8923
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8924 446 scr_has_flags |= SCRHAS_ITEM;
8925
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8926 28 scr_has_flags |= SCRHAS_TWARP;
8927
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8928 {
8929
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32706 times.
65588 if(screen.tilewarptype[q]
8930
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8931
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8932 {
8933 176 scr_has_flags |= SCRHAS_TWARP;
8934 176 break;
8935 }
8936 32706 }
8937
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 8344 times.
✗ Branch 3 not taken.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8938
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8939 36 scr_has_flags |= SCRHAS_SWARP;
8940
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8941 {
8942
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 16298 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8943
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8944
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8945 {
8946 4270 scr_has_flags |= SCRHAS_SWARP;
8947 4270 break;
8948 }
8949 16298 }
8950
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8951 44 scr_has_flags |= SCRHAS_WARPRET;
8952
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8953 {
8954
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 30208 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8955 {
8956 784 scr_has_flags |= SCRHAS_WARPRET;
8957 784 break;
8958 }
8959 30208 }
8960
8961
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8962 scr_has_flags |= SCRHAS_LAYERS;
8963
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8964 {
8965
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 44532 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8966
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8967 {
8968 966 scr_has_flags |= SCRHAS_LAYERS;
8969 966 break;
8970 }
8971 44532 }
8972
8973
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8974 10 scr_has_flags |= SCRHAS_MAZE;
8975
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8976 scr_has_flags |= SCRHAS_MAZE;
8977
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8978 {
8979
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8980 {
8981 scr_has_flags |= SCRHAS_MAZE;
8982 break;
8983 }
8984 33480 }
8985
8986
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8987
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8988
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8989 2968 scr_has_flags |= SCRHAS_D_S_U;
8990
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8991 {
8992
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8993 {
8994 5212 scr_has_flags |= SCRHAS_D_S_U;
8995 5212 break;
8996 }
8997 800 }
8998
8999
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
9000
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
9001
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
9002
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
9003
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
9004
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
9005 8380 scr_has_flags |= SCRHAS_FLAGS;
9006
9007
2/2
✓ Branch 0 taken 8322 times.
✓ Branch 1 taken 58 times.
8380 if(screen.pattern)
9008 58 scr_has_flags |= SCRHAS_ENEMY;
9009
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
9010 {
9011
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
9012 {
9013 1014 scr_has_flags |= SCRHAS_ENEMY;
9014 1014 break;
9015 }
9016 73086 }
9017
9018
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8346 times.
16726 if(screen.noreset || screen.nocarry
9019
3/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8346 times.
✓ Branch 3 taken 34 times.
8380 || screen.nextmap || screen.nextscr)
9020 34 scr_has_flags |= SCRHAS_CARRY;
9021
9022
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
9023 22 scr_has_flags |= SCRHAS_SCRIPT;
9024
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
9025 {
9026
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
9027 {
9028 scr_has_flags |= SCRHAS_SCRIPT;
9029 break;
9030 }
9031 66864 }
9032
9033
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
9034 {
9035
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
9036
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9037
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9038 {
9039 3076 scr_has_flags |= SCRHAS_SECRETS;
9040 3076 break;
9041 }
9042 680916 }
9043
9044
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9045 {
9046
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9047
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9048 {
9049 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9050 5360 break;
9051 }
9052 568532 }
9053
9054
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9055
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9056
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9057 || screen.timedwarptics || screen.screen_midi != -1
9058 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9059 8380 scr_has_flags |= SCRHAS_MISC;
9060
9061
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9062 return qe_invalid;
9063
9064 //Write stuff
9065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9066 {
9067
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9068 return qe_invalid;
9069
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9070 return qe_invalid;
9071
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9072 return qe_invalid;
9073
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9074 return qe_invalid;
9075
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9076 return qe_invalid;
9077
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9078 return qe_invalid;
9079
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9080 return qe_invalid;
9081 8380 }
9082
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9083 {
9084
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9085 return qe_invalid;
9086
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9087 return qe_invalid;
9088
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9089 return qe_invalid;
9090
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9091 return qe_invalid;
9092 446 }
9093
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9094 {
9095
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9096 return qe_invalid;
9097 4374 }
9098
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9099 {
9100
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9101 {
9102
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9103 return qe_invalid;
9104 816 }
9105
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9106 {
9107
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9108 return qe_invalid;
9109 816 }
9110
9111
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9112 {
9113
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9114 return qe_invalid;
9115 816 }
9116
9117
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9118 return qe_invalid;
9119 204 }
9120
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9121 {
9122
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9123 {
9124
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9125 return qe_invalid;
9126 17224 }
9127
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9128 {
9129
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9130 return qe_invalid;
9131 17224 }
9132
9133
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9134 {
9135
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9136 return qe_invalid;
9137 17224 }
9138
9139
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9140 return qe_invalid;
9141
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9142 return qe_invalid;
9143 4306 }
9144
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9145 {
9146
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9147 {
9148
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9149 return qe_invalid;
9150 3312 }
9151
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9152 {
9153
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9154 return qe_invalid;
9155 3312 }
9156
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9157 return qe_invalid;
9158
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9159 return qe_invalid;
9160 828 }
9161
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9162 {
9163
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9164 {
9165
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9166 return qe_invalid;
9167 5796 }
9168
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9169 {
9170
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9171 return qe_invalid;
9172 5796 }
9173
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9174 {
9175
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9176 return qe_invalid;
9177 5796 }
9178
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9179 return qe_invalid;
9180
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9181 return qe_invalid;
9182 966 }
9183
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9184 {
9185
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9186 {
9187
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9188 return qe_invalid;
9189 40 }
9190
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9191 return qe_invalid;
9192
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9193 return qe_invalid;
9194 10 }
9195
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9196 {
9197
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9198 return qe_invalid;
9199
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9200 {
9201
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9202 return qe_invalid;
9203 32720 }
9204
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9205 return qe_invalid;
9206
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9207 return qe_invalid;
9208
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9209 return qe_invalid;
9210
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9211 return qe_invalid;
9212 8180 }
9213
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9214 {
9215
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9216 return qe_invalid;
9217
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9218 return qe_invalid;
9219
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9220 return qe_invalid;
9221
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9222 return qe_invalid;
9223
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9224 return qe_invalid;
9225
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9226 return qe_invalid;
9227
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9228 return qe_invalid;
9229
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9230 return qe_invalid;
9231
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9232 return qe_invalid;
9233
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9234 return qe_invalid;
9235
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9236 return qe_invalid;
9237 1294 }
9238
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9239 {
9240
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9241 {
9242
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9243 return qe_invalid;
9244 10720 }
9245
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9246 return qe_invalid;
9247 1072 }
9248
2/2
✓ Branch 0 taken 8346 times.
✓ Branch 1 taken 34 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9249 {
9250
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 if(!p_iputw(screen.noreset,f))
9251 return qe_invalid;
9252
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 if(!p_iputw(screen.nocarry,f))
9253 return qe_invalid;
9254
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 if(!p_putc(screen.nextmap,f))
9255 return qe_invalid;
9256
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 if(!p_putc(screen.nextscr,f))
9257 return qe_invalid;
9258 34 }
9259
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9260 {
9261
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9262 return qe_invalid;
9263
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9264 return qe_invalid;
9265
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9266 {
9267
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9268 return qe_invalid;
9269 176 }
9270 22 }
9271
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9272 {
9273
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9274 {
9275
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9276 return qe_invalid;
9277 393728 }
9278
9279
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9280 {
9281
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9282 return qe_invalid;
9283 393728 }
9284
9285
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9286 {
9287
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9288 return qe_invalid;
9289 393728 }
9290 3076 }
9291
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9292 {
9293
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9294 {
9295
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9296 return qe_invalid;
9297 943360 }
9298
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9299 {
9300
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9301 return qe_invalid;
9302 943360 }
9303
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9304 {
9305
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9306 return qe_invalid;
9307 943360 }
9308 5360 }
9309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9310 {
9311
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9312 return qe_invalid;
9313
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9314 return qe_invalid;
9315
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9316 return qe_invalid;
9317
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9318 return qe_invalid;
9319
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9320 return qe_invalid;
9321
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9322 return qe_invalid;
9323
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9324 return qe_invalid;
9325
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9326 return qe_invalid;
9327
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9328 return qe_invalid;
9329
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_show,f))
9330 return qe_invalid;
9331
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9332 return qe_invalid;
9333 8380 }
9334
9335 8380 dword numffc = screen.numFFC();
9336
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9337 return qe_invalid;
9338
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9339 {
9340 245678 ffcdata const& tempffc = screen.ffcs[k];
9341
9342
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9343 return qe_invalid;
9344
9345
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9346 243364 continue;
9347
9348
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9349 return qe_invalid;
9350
9351
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9352 return qe_invalid;
9353
9354
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9355 return qe_invalid;
9356
9357
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9358 return qe_invalid;
9359
9360
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9361 return qe_invalid;
9362
9363
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9364 return qe_invalid;
9365
9366
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9367 return qe_invalid;
9368
9369
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9370 return qe_invalid;
9371
9372
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9373 return qe_invalid;
9374
9375
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9376 return qe_invalid;
9377
9378
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9379 return qe_invalid;
9380
9381
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9382 return qe_invalid;
9383
9384
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9385 return qe_invalid;
9386
9387
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9388 return qe_invalid;
9389
9390
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9391 return qe_invalid;
9392
9393
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9394 {
9395
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9396 return qe_invalid;
9397 18512 }
9398
9399
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9400 return qe_invalid;
9401 2314 }
9402
9403
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9404 return qe_invalid;
9405
9406 8380 return qe_OK;
9407 12784 }
9408
9409 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9410 {
9411 9 dword section_id=ID_MAPS;
9412 9 dword section_version=V_MAPS;
9413 9 dword section_size = 0;
9414
9415 //section id
9416
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9417 {
9418 new_return(1);
9419 }
9420
9421 //section version info
9422
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9423 {
9424 new_return(2);
9425 }
9426
9427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9428 {
9429 new_return(3);
9430 }
9431
9432
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9433 {
9434 18 fake_pack_writing=(writecycle==0);
9435
9436 //section size
9437
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9438 {
9439 new_return(4);
9440 }
9441
9442 18 writesize=0;
9443
9444
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9445 {
9446 new_return(5);
9447 }
9448 18 map_autolayers.resize(map_count*6);
9449
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9450 {
9451 100 byte valid = 0;
9452
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9453 {
9454
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9455 break;
9456 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9457
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9458 {
9459 94 valid = 1;
9460 94 break;
9461 }
9462 1188 }
9463
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9464 {
9465 new_return(6);
9466 }
9467
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9468
9469 { //per-map info
9470
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9471 {
9472 564 size_t ind = i*6+q;
9473
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(map_autolayers[ind],f))
9474 new_return(7);
9475 564 }
9476
9477
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9478 {
9479
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9480 {
9481
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9482 {
9483 new_return(8);
9484 }
9485 6016 }
9486 752 }
9487 }
9488
9489
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9490 12784 writemapscreen(f,i,j);
9491 94 }
9492
9493
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9494 {
9495 9 section_size=writesize;
9496 9 }
9497 18 }
9498
9499
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9500 {
9501 char ebuf[80];
9502 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9503 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9504 }
9505
9506 9 new_return(0);
9507 }
9508
9509 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9510 {
9511 //Check what needs writing
9512 byte combo_has_flags = 0;
9513 1029676 for(auto q = 0; q < 8; ++q)
9514 {
9515 2059352 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9516 1029676 || (q < 4 && tmp_cmb.attributes[q]))
9517 {
9518 combo_has_flags |= CHAS_ATTRIB;
9519 break;
9520 }
9521 1029676 }
9522
3/4
✓ Branch 0 taken 258514 times.
✓ Branch 1 taken 258514 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 258446 times.
258446 if (tmp_cmb.triggerflags[0] || tmp_cmb.triggerflags[1]
9523
3/4
✓ Branch 0 taken 258512 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258512 times.
✗ Branch 3 not taken.
258514 || tmp_cmb.triggerflags[2] || tmp_cmb.triggerflags[3]
9524
3/4
✓ Branch 0 taken 258510 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258512 || tmp_cmb.triggerflags[4] || tmp_cmb.triggerflags[5]
9525
2/4
✓ Branch 0 taken 258510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258510 || tmp_cmb.triggerlevel || tmp_cmb.trig_lstate
9526
2/4
✓ Branch 0 taken 258510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258510 || tmp_cmb.trig_gstate || tmp_cmb.trig_statetime
9527
2/4
✓ Branch 0 taken 258510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258510 || tmp_cmb.triggerbtn || tmp_cmb.triggeritem
9528
2/4
✓ Branch 0 taken 258510 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258510 times.
✗ Branch 3 not taken.
258510 || tmp_cmb.trigtimer || tmp_cmb.trigsfx
9529
4/4
✓ Branch 0 taken 258448 times.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 258446 times.
✓ Branch 3 taken 2 times.
258510 || tmp_cmb.trigchange || tmp_cmb.trigprox
9530
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trigctr || tmp_cmb.trigctramnt
9531
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.triglbeam || tmp_cmb.trigcschange
9532
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.spawnitem || tmp_cmb.spawnenemy
9533
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.exstate > -1 || tmp_cmb.spawnip
9534
1/2
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
258446 || tmp_cmb.exdoor_dir > -1
9535
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trigcopycat || tmp_cmb.trigcooldown
9536
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_genscr || tmp_cmb.trig_group
9537
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_group_val || tmp_cmb.trig_levelitems
9538
1/2
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
258446 || tmp_cmb.trigdmlevel > -1
9539
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.triglvlpalette > -1 || tmp_cmb.trigbosspalette > -1
9540
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trigquaketime > -1 || tmp_cmb.trigwavytime > -1
9541
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_swjinxtime > -2 || tmp_cmb.trig_itmjinxtime > -2
9542
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_stuntime > -2 || tmp_cmb.trig_bunnytime > -2
9543
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.trig_pushtime != 8 || tmp_cmb.trig_shieldjinxtime > -2
9544
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.prompt_cid || tmp_cmb.prompt_cs
9545
2/4
✓ Branch 0 taken 258446 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258446 times.
✗ Branch 3 not taken.
258446 || tmp_cmb.prompt_x != 12 || tmp_cmb.prompt_y != -8)
9546 258582 combo_has_flags |= CHAS_TRIG;
9547
2/2
✓ Branch 0 taken 775338 times.
✓ Branch 1 taken 258446 times.
1033784 else for(int q = 0; q < 3; ++q)
9548
1/2
✓ Branch 0 taken 775338 times.
✗ Branch 1 not taken.
775338 if(tmp_cmb.trigtint[q])
9549 combo_has_flags |= CHAS_TRIG;
9550
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 258400 times.
✓ Branch 2 taken 258102 times.
✓ Branch 3 taken 526 times.
517028 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9551 516502 combo_has_flags |= CHAS_FLAG;
9552
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 250982 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 243350 times.
✓ Branch 5 taken 12086 times.
232088 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9553
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9554
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9555 514874 combo_has_flags |= CHAS_ANIM;
9556
4/4
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 218646 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
40260 if(tmp_cmb.script || tmp_cmb.label.size())
9557 218652 combo_has_flags |= CHAS_SCRIPT;
9558
2/2
✓ Branch 0 taken 2071200 times.
✓ Branch 1 taken 258900 times.
2330100 else for(auto q = 0; q < 8; ++q)
9559 {
9560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2071200 times.
2071200 if(tmp_cmb.initd[q])
9561 {
9562 combo_has_flags |= CHAS_SCRIPT;
9563 break;
9564 }
9565 2071200 }
9566
6/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 300648 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✓ Branch 4 taken 218646 times.
✓ Branch 5 taken 42254 times.
653944 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9567
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9568 519806 combo_has_flags |= CHAS_BASIC;
9569
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 134130 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
383664 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9570
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9571
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9572
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9573
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9574
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9575
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftlightrad || tmp_cmb.liftlightshape
9576
1/2
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
258896 || tmp_cmb.lift_parent_item)
9577 393028 combo_has_flags |= CHAS_LIFT;
9578
3/4
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 134122 times.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
649734 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9579
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9580
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9581
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9582
2/4
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning)
9583 393028 combo_has_flags |= CHAS_GENERAL;
9584
9585
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 134122 times.
393028 if(!p_putc(combo_has_flags,f))
9586 {
9587 134122 return 50;
9588 }
9589
2/2
✓ Branch 0 taken 82514 times.
✓ Branch 1 taken 176392 times.
258906 if(!combo_has_flags) return 0; //Valid, done reading
9590 //Write the combo
9591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82514 times.
82514 if(combo_has_flags&CHAS_BASIC)
9592 {
9593
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9594 return 6;
9595
9596
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9597 return 7;
9598
9599
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9600 return 8;
9601
9602
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9603 return 9;
9604
9605
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9606 return 15;
9607
9608
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9609 return 10;
9610 82514 }
9611
2/2
✓ Branch 0 taken 82508 times.
✓ Branch 1 taken 6 times.
82514 if(combo_has_flags&CHAS_SCRIPT)
9612 {
9613 6 p_putcstr(tmp_cmb.label, f);
9614
9615
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9616 return 26;
9617
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9619 return 27;
9620 6 }
9621
2/2
✓ Branch 0 taken 54340 times.
✓ Branch 1 taken 28174 times.
82514 if(combo_has_flags&CHAS_ANIM)
9622 {
9623
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9624 return 11;
9625
9626
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9627 return 12;
9628
9629
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9630 return 13;
9631
9632
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9633 return 14;
9634
9635
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9636 return 16;
9637
9638
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9639 return 18;
9640
9641
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9642 return 19;
9643 28174 }
9644
2/2
✓ Branch 0 taken 79324 times.
✓ Branch 1 taken 3190 times.
82514 if(combo_has_flags&CHAS_ATTRIB)
9645 {
9646
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9647
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12760 times.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9648 return 20;
9649
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9650
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25520 times.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9651 return 25;
9652
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9653
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25520 times.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9654 return 32;
9655 3190 }
9656
2/2
✓ Branch 0 taken 82216 times.
✓ Branch 1 taken 298 times.
82514 if(combo_has_flags&CHAS_FLAG)
9657 {
9658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 298 times.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9659 return 21;
9660
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9661 return 33;
9662 298 }
9663
2/2
✓ Branch 0 taken 82054 times.
✓ Branch 1 taken 460 times.
82514 if(combo_has_flags&CHAS_TRIG)
9664 {
9665
2/2
✓ Branch 0 taken 2760 times.
✓ Branch 1 taken 460 times.
3220 for ( int32_t q = 0; q < 6; q++ )
9666
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2760 times.
2760 if(!p_iputl(tmp_cmb.triggerflags[q],f))
9667 return 22;
9668
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.triggerlevel,f))
9669 return 23;
9670
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.triggerbtn,f))
9671 return 34;
9672
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.triggeritem,f))
9673 return 35;
9674
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigtimer,f))
9675 return 36;
9676
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigsfx,f))
9677 return 37;
9678
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.trigchange,f))
9679 return 38;
9680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_cmb.trigprox,f))
9681 return 39;
9682
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigctr,f))
9683 return 40;
9684
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.trigctramnt,f))
9685 return 41;
9686
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.triglbeam,f))
9687 return 42;
9688
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigcschange,f))
9689 return 43;
9690
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.spawnitem,f))
9691 return 44;
9692
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.spawnenemy,f))
9693 return 45;
9694
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.exstate,f))
9695 return 46;
9696
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.spawnip,f))
9697 return 47;
9698
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigcopycat,f))
9699 return 48;
9700
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trigcooldown,f))
9701 return 49;
9702
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.prompt_cid,f))
9703 return 50;
9704
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.prompt_cs,f))
9705 return 51;
9706
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.prompt_x,f))
9707 return 52;
9708
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.prompt_y,f))
9709 return 53;
9710
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_lstate,f))
9711 return 69;
9712
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_gstate,f))
9713 return 70;
9714
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_cmb.trig_statetime,f))
9715 return 71;
9716
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_genscr,f))
9717 return 72;
9718
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_group,f))
9719 return 76;
9720
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_group_val,f))
9721 return 77;
9722
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.exdoor_dir,f))
9723 return 89;
9724
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.exdoor_ind,f))
9725 return 90;
9726
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_levelitems,f))
9727 return 91;
9728
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trigdmlevel,f))
9729 return 92;
9730
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9731
1/2
✓ Branch 0 taken 1380 times.
✗ Branch 1 not taken.
1380 if(!p_iputw(tmp_cmb.trigtint[q],f))
9732 return 93;
9733
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.triglvlpalette,f))
9734 return 94;
9735
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trigbosspalette,f))
9736 return 95;
9737
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trigquaketime,f))
9738 return 96;
9739
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trigwavytime,f))
9740 return 97;
9741
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_swjinxtime,f))
9742 return 98;
9743
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_itmjinxtime,f))
9744 return 99;
9745
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_stuntime,f))
9746 return 100;
9747
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_cmb.trig_bunnytime,f))
9748 return 101;
9749
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.trig_pushtime,f))
9750 return 102;
9751
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_cmb.trig_shieldjinxtime, f))
9752 return 103;
9753 460 }
9754
2/2
✓ Branch 0 taken 82504 times.
✓ Branch 1 taken 10 times.
82514 if(combo_has_flags&CHAS_LIFT)
9755 {
9756
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(tmp_cmb.liftcmb,f))
9757 return 54;
9758
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftcs,f))
9759 return 55;
9760
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(tmp_cmb.liftundercmb,f))
9761 return 56;
9762
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftundercs,f))
9763 return 57;
9764
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftdmg,f))
9765 return 58;
9766
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftlvl,f))
9767 return 59;
9768
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftitm,f))
9769 return 60;
9770
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftflags,f))
9771 return 61;
9772
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftgfx,f))
9773 return 62;
9774
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftsprite,f))
9775 return 63;
9776
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftsfx,f))
9777 return 64;
9778
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9779 return 65;
9780
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9781 return 66;
9782
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.lifthei,f))
9783 return 67;
9784
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.lifttime,f))
9785 return 68;
9786
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.lift_parent_item,f))
9787 return 78;
9788
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftlightrad,f))
9789 return 96;
9790
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(tmp_cmb.liftlightshape,f))
9791 return 97;
9792 10 }
9793
2/2
✓ Branch 0 taken 80314 times.
✓ Branch 1 taken 2200 times.
82514 if(combo_has_flags&CHAS_GENERAL)
9794 {
9795
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9796 return 73;
9797
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9798 return 74;
9799
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9800 return 75;
9801
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9802 return 79;
9803
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9804 return 80;
9805
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9806 return 81;
9807
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9808 return 82;
9809
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9810 return 83;
9811
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9812 return 84;
9813
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9814 return 85;
9815
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9816 return 86;
9817
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9818 return 87;
9819
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9820 return 88;
9821
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9822 return 89;
9823
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9824 return 90;
9825
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9826 return 91;
9827
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9828 return 92;
9829
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9830 return 93;
9831
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9832 return 94;
9833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9834 return 95;
9835 2200 }
9836 82514 return 0;
9837 393028 }
9838
9839 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9840 {
9841 //these are here to bypass compiler warnings about unused arguments
9842 9 version=version;
9843 9 build=build;
9844
9845 word combos_used;
9846 9 dword section_id=ID_COMBOS;
9847 9 dword section_version=V_COMBOS;
9848 // dword section_size=0;
9849 9 combos_used = count_combos()-start_combo;
9850
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9851
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9852 9 dword section_size = 0;
9853
9854 //section id
9855
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9856 {
9857 new_return(1);
9858 }
9859
9860 //section version info
9861
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9862 {
9863 new_return(2);
9864 }
9865
9866
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9867 {
9868 new_return(3);
9869 }
9870
9871
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9872 {
9873 18 fake_pack_writing=(writecycle==0);
9874
9875 //section size
9876
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9877 {
9878 new_return(4);
9879 }
9880
9881 18 writesize=0;
9882
9883 //finally... section data
9884 18 combos_used=count_combos()-start_combo;
9885
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9886
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9887
9888
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9889 {
9890 new_return(5);
9891 }
9892
9893 18 size_t end_combo = start_combo+combos_used;
9894
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9895 {
9896 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9897
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9898 258906 }
9899
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9900 {
9901 9 section_size=writesize;
9902 9 }
9903 18 }
9904
9905
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9906 {
9907 char ebuf[80];
9908 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9909 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9910 }
9911
9912 9 new_return(0);
9913 9 }
9914
9915 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9916 {
9917 //these are here to bypass compiler warnings about unused arguments
9918 9 version=version;
9919 9 build=build;
9920
9921 9 dword section_id=ID_COMBOALIASES;
9922 9 dword section_version=V_COMBOALIASES;
9923 9 dword section_size=0;
9924
9925 //section id
9926
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9927 {
9928 new_return(1);
9929 }
9930
9931 //section version info
9932
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9933 {
9934 new_return(2);
9935 }
9936
9937
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9938 {
9939 new_return(3);
9940 }
9941
9942
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9943 {
9944 18 fake_pack_writing=(writecycle==0);
9945
9946 //section size
9947
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9948 {
9949 new_return(4);
9950 }
9951
9952 18 writesize=0;
9953
9954 //finally... section data
9955
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9956 {
9957
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
9958 {
9959 new_return(5);
9960 }
9961
9962
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
9963 {
9964 new_return(6);
9965 }
9966
9967 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9968
9969
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
9970 {
9971 new_return(7);
9972 }
9973
9974
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
9975 {
9976 new_return(8);
9977 }
9978
9979
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
9980 {
9981 new_return(9);
9982 }
9983
9984
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
9985 {
9986
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
9987 {
9988 new_return(10);
9989 }
9990 149596 }
9991
9992
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
9993 {
9994
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
9995 {
9996 new_return(11);
9997 }
9998 149596 }
9999 147456 }
10000
10001 //Combo pools!
10002 int16_t num_cpools;
10003
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10004 {
10005
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10006 {
10007 2 ++num_cpools;
10008 2 break;
10009 }
10010 147450 }
10011
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10012
10013
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10014 {
10015 new_return(12);
10016 }
10017
10018
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10019 {
10020 6 combo_pool const& pool = combo_pools[cp];
10021 6 int32_t num_combos = pool.combos.size();
10022
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10023 {
10024 new_return(13);
10025 }
10026
10027
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10028 {
10029 26 cpool_entry const& entry = pool.combos.at(q);
10030
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10031 {
10032 new_return(14);
10033 }
10034
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10035 {
10036 new_return(15);
10037 }
10038
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10039 {
10040 new_return(16);
10041 }
10042 26 }
10043 6 }
10044
10045 //Autocombos!
10046 int16_t num_cautos;
10047
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10048 {
10049
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10050 {
10051 ++num_cautos;
10052 break;
10053 }
10054 147456 }
10055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10056
10057
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10058 {
10059 new_return(17);
10060 }
10061
10062
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10063 {
10064 combo_auto const& cauto = combo_autos[ca];
10065 if (!p_putc(cauto.getType(), f))
10066 {
10067 new_return(18);
10068 }
10069 if (!p_iputl(cauto.getIconDisplay(), f))
10070 {
10071 new_return(19);
10072 }
10073 if (!p_iputl(cauto.getEraseCombo(), f))
10074 {
10075 new_return(20);
10076 }
10077 if (!p_putc(cauto.getFlags(), f))
10078 {
10079 new_return(21);
10080 }
10081 if (!p_putc(cauto.getArg(), f))
10082 {
10083 new_return(22);
10084 }
10085 int32_t num_combos = cauto.combos.size();
10086 if (!p_iputl(num_combos, f))
10087 {
10088 new_return(23);
10089 }
10090
10091 for (auto q = 0; q < num_combos; ++q)
10092 {
10093 autocombo_entry const& entry = cauto.combos.at(q);
10094 if (!p_putc(entry.ctype, f))
10095 {
10096 new_return(24);
10097 }
10098 if (!p_iputl(entry.cid, f))
10099 {
10100 new_return(25);
10101 }
10102 }
10103 }
10104
10105
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10106 {
10107 9 section_size=writesize;
10108 9 }
10109 18 }
10110
10111
10112
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10113 {
10114 char ebuf[80];
10115 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10116 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10117 }
10118
10119 9 new_return(0);
10120 }
10121
10122 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10123 {
10124 //these are here to bypass compiler warnings about unused arguments
10125 9 version=version;
10126 9 build=build;
10127 9 start_cset=start_cset;
10128 9 max_csets=max_csets;
10129
10130 9 dword section_id=ID_CSETS;
10131 9 dword section_version=V_CSETS;
10132 9 int32_t palcycles = count_palcycles(&QMisc);
10133 // int32_t palcyccount = count_palcycles(&QMisc);
10134 9 dword section_size = 0;
10135
10136 //section id
10137
10138
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10139 {
10140 new_return(1);
10141 }
10142
10143 //section version info
10144
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10145 {
10146 new_return(2);
10147 }
10148
10149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10150 {
10151 new_return(3);
10152 }
10153
10154
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10155 {
10156 18 fake_pack_writing=(writecycle==0);
10157
10158 //section size
10159
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10160 {
10161 new_return(4);
10162 }
10163
10164 18 writesize=0;
10165
10166 //finally... section data
10167
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10168 {
10169 new_return(5);
10170 }
10171
10172
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10173 {
10174 new_return(6);
10175 }
10176
10177
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10178 {
10179 new_return(15);
10180 }
10181
10182
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10183 {
10184
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10185 {
10186
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10187 {
10188 new_return(16);
10189 }
10190 1650 }
10191
10192
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10193 {
10194
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10195 {
10196 new_return(17);
10197 }
10198 1650 }
10199
10200
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10201 {
10202
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10203 {
10204 new_return(18);
10205 }
10206 1650 }
10207 550 }
10208
10209
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10210 {
10211 9 section_size=writesize;
10212 9 }
10213 18 }
10214
10215
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10216 {
10217 char ebuf[80];
10218 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10219 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10220 }
10221
10222 9 new_return(0);
10223 }
10224
10225 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10226 {
10227 //these are here to bypass compiler warnings about unused arguments
10228 9 version=version;
10229 9 build=build;
10230 9 start_msgstr=start_msgstr;
10231 9 max_msgstrs=max_msgstrs;
10232
10233 9 dword section_id=ID_STRINGS;
10234 9 dword section_version=V_STRINGS;
10235 9 dword section_size = 0;
10236
10237 //section id
10238
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10239 {
10240 new_return(1);
10241 }
10242
10243 //section version info
10244
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10245 {
10246 new_return(2);
10247 }
10248
10249
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10250 {
10251 new_return(3);
10252 }
10253
10254
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10255 {
10256 18 fake_pack_writing=(writecycle==0);
10257
10258 //section size
10259
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10260 {
10261 new_return(4);
10262 }
10263
10264 18 writesize=0;
10265
10266 //finally... section data
10267
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10268 {
10269 return qe_invalid;
10270 }
10271
10272
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10273 {
10274 836 int32_t sz = MsgStrings[i].s.size();
10275
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10276
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10277 {
10278 return qe_invalid;
10279 }
10280
10281 836 char const* tmpstr = MsgStrings[i].s.c_str();
10282
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10283 {
10284
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10285 {
10286 return qe_invalid;
10287 }
10288 836 }
10289
10290
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10291 {
10292 return qe_invalid;
10293 }
10294
10295
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10296 {
10297 return qe_invalid;
10298 }
10299
10300
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10301 {
10302 return qe_invalid;
10303 }
10304
10305
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10306 {
10307 return qe_invalid;
10308 }
10309
10310
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10311 {
10312 return qe_invalid;
10313 }
10314
10315
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10316 {
10317 return qe_invalid;
10318 }
10319
10320
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10321 {
10322 return qe_invalid;
10323 }
10324
10325
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10326 {
10327 return qe_invalid;
10328 }
10329
10330
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10331 {
10332 return qe_invalid;
10333 }
10334
10335
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10336 {
10337 return qe_invalid;
10338 }
10339
10340
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10341 {
10342 return qe_invalid;
10343 }
10344
10345
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10346 {
10347 return qe_invalid;
10348 }
10349
10350
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10351 {
10352
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10353 {
10354 return qe_invalid;
10355 }
10356 3344 }
10357
10358
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10359 {
10360 return qe_invalid;
10361 }
10362
10363
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10364 {
10365 return qe_invalid;
10366 }
10367
10368
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10369 {
10370 return qe_invalid;
10371 }
10372
10373
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10374 {
10375 return qe_invalid;
10376 }
10377
10378
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10379 {
10380 return qe_invalid;
10381 }
10382
10383
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10384 {
10385 return qe_invalid;
10386 }
10387
10388
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10389 {
10390 return qe_invalid;
10391 }
10392
10393
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10394 {
10395 return qe_invalid;
10396 }
10397
10398
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10399 {
10400 return qe_invalid;
10401 }
10402
10403
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10404 {
10405 return qe_invalid;
10406 }
10407
10408
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10409 {
10410 return qe_invalid;
10411 }
10412 836 }
10413
10414
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10415 {
10416 9 section_size=writesize;
10417 9 }
10418 18 }
10419
10420
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10421 {
10422 char ebuf[80];
10423 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10424 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10425 }
10426
10427 9 new_return(0);
10428 9 }
10429
10430 int32_t writestrings_text(PACKFILE *f)
10431 {
10432 std::map<int32_t, int32_t> msglistcache;
10433
10434 for(int32_t index = 1; index<msg_count; index++)
10435 {
10436 for(int32_t i=1; i<msg_count; i++)
10437 {
10438 if(MsgStrings[i].listpos==index)
10439 {
10440 msglistcache[index-1]=i;
10441 break;
10442 }
10443 }
10444 }
10445
10446 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10447 {
10448 fake_pack_writing=(writecycle==0);
10449 char ebuf[32];
10450
10451 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10452
10453 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10454 {
10455 return qe_invalid;
10456 }
10457
10458 for(int32_t i=1; i<msg_count; i++)
10459 {
10460 int32_t str = msglistcache[i-1];
10461
10462 if(!str)
10463 continue;
10464
10465 if(MsgStrings[str].nextstring != 0)
10466 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10467 else
10468 sprintf(ebuf,"\n\n___%d___\n", str);
10469
10470 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10471 {
10472 return qe_invalid;
10473 }
10474
10475 std::string text = MsgStrings[str].serialize();
10476 if (!pfwrite(text.c_str(), text.size(), f))
10477 {
10478 return qe_invalid;
10479 }
10480 }
10481 }
10482
10483 new_return(0);
10484 }
10485
10486 1 int32_t writestrings_tsv(PACKFILE *f)
10487 {
10488 1 std::stringstream ss;
10489
10490
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10491
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10492
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10493
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10494
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10495
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10496
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10497
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10498
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10499
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10500
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10501
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10502
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10503
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10504
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10505
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10506
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10507
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10508
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10509
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10510
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10511
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10512
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10513
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10514
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10515
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10516 };
10517
10518
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10519 {
10520
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10521
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10522 1 break;
10523
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10524 }
10525
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10526
10527 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10528
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10529
10530
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10531 {
10532 35 auto& msg = MsgStrings[i];
10533
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10534 {
10535
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10536
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10537
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10538 35 break;
10539
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10540
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10541
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10542 35 }
10543
10544
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10545
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10546 {
10547 return qe_invalid;
10548 }
10549
10550 1 new_return(0);
10551 1 }
10552
10553 std::string parse_to_legacy_msg_str_encoding(std::string const& s);
10554
10555 void parse_strings_tsv(std::string tsv)
10556 {
10557 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10558 { "message", [](auto& msg, auto& text){ msg.setFromLegacyEncoding(parse_to_legacy_msg_str_encoding(text)); } },
10559 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10560 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10561 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10562 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10563 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10564 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10565 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10566 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10567 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10568 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10569 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10570 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10571 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10572 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10573 { "margin", [&](auto& msg, auto& text){
10574 std::vector<std::string> strs;
10575 util::split(text, strs, ' ');
10576 if (strs.size() != 4)
10577 throw std::runtime_error("margin field must have 4 components");
10578 msg.margins[0] = std::stoi(strs[0]);
10579 msg.margins[1] = std::stoi(strs[1]);
10580 msg.margins[2] = std::stoi(strs[2]);
10581 msg.margins[3] = std::stoi(strs[3]);
10582 } },
10583 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10584 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10585 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10586 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10587 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10588 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10589 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10590 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10591 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10592 };
10593
10594 std::vector<std::string> rows;
10595 util::split(tsv, rows, '\n');
10596 if (rows.size())
10597 {
10598 std::string last = rows.back();
10599 util::trimstr(last);
10600 if (last.empty())
10601 rows.pop_back();
10602 }
10603 if (rows.size() <= 1)
10604 throw std::runtime_error("missing header row");
10605
10606 std::vector<std::string> columns;
10607 util::split(rows[0], columns, '\t');
10608 for (auto name : columns)
10609 {
10610 if (!fields.contains(name))
10611 throw std::runtime_error(fmt::format("invalid field: {}", name));
10612 }
10613
10614 int start_index = 1;
10615 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10616 start_index += 1;
10617
10618 int num_strings = rows.size() - start_index + 1;
10619 if (num_strings > MAXMSGS-1)
10620 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10621
10622 std::vector<MsgStr> msgs;
10623 msgs.reserve(num_strings);
10624 for (int i = start_index; i < rows.size(); i++)
10625 {
10626 std::vector<std::string> strs;
10627 util::split(rows[i], strs, '\t');
10628 if (strs.size() != columns.size())
10629 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10630
10631 int j = 0;
10632 auto& msg = msgs.emplace_back();
10633 for (auto& name : columns)
10634 {
10635 auto& fn = fields[name];
10636 try
10637 {
10638 fn(msg, strs[j++]);
10639 }
10640 catch (std::exception& ex)
10641 {
10642 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10643 }
10644 }
10645 }
10646
10647 init_msgstrings(0, msgs.size());
10648 for (int i = 0; i < msgs.size(); i++)
10649 MsgStrings[i + 1] = msgs[i];
10650 msg_count = msgs.size();
10651 msglistcache.clear();
10652 }
10653
10654 bool isblanktile(tiledata *buf, int32_t i);
10655 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10656 {
10657 //these are here to bypass compiler warnings about unused arguments
10658 9 version=version;
10659 9 build=build;
10660
10661 int32_t tiles_used;
10662 9 dword section_id=ID_TILES;
10663 9 dword section_version=V_TILES;
10664 9 al_trace("Counting tiles used\n");
10665 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10666
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10667
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10668 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10669 9 dword section_size = 0;
10670
10671 //section id
10672
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10673 {
10674 new_return(1);
10675 }
10676
10677 //section version info
10678
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10679 {
10680 new_return(2);
10681 }
10682
10683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10684 {
10685 new_return(3);
10686 }
10687
10688
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10689 {
10690 18 fake_pack_writing=(writecycle==0);
10691
10692 //section size
10693
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10694 {
10695 new_return(4);
10696 }
10697
10698 18 writesize=0;
10699
10700 //finally... section data
10701 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10702
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10703
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10704
10705
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10706 {
10707 new_return(5);
10708 }
10709
10710
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10711 {
10712
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10713 {
10714
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10715 new_return(8);
10716 365770 }
10717 else
10718 {
10719 330614 int format = newtilebuf[start_tile+i].format;
10720
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10721 {
10722 new_return(6);
10723 }
10724
10725
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10726 {
10727 byte temp_tile[128];
10728 327742 byte *di = temp_tile;
10729 327742 byte *src = newtilebuf[start_tile+i].data;
10730
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10731 {
10732 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10733 41950976 ++di;
10734 41950976 }
10735
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10736 {
10737 new_return(7);
10738 }
10739 327742 }
10740
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10741 {
10742 new_return(7);
10743 }
10744 }
10745 696384 }
10746
10747
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10748 {
10749 9 section_size=writesize;
10750 9 }
10751 18 }
10752
10753
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10754 {
10755 char ebuf[80];
10756 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10757 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10758 }
10759
10760 9 new_return(0);
10761 }
10762
10763 /* MIDI Format
10764 section_id LONG
10765 section_version WORD
10766 section_cversion WORD
10767 section_size LONG
10768 midi_flags 32 Byte ? BITFIELD[252]
10769
10770 [
10771 title 36
10772 start 4
10773 loop_start 4
10774 loop_end 4
10775 loop 2
10776 volume 2
10777 midi *
10778 ]
10779
10780 */
10781
10782 9 int32_t writemidis(PACKFILE *f)
10783 {
10784 9 dword section_id=ID_MIDIS;
10785 9 dword section_version=V_MIDIS;
10786 9 dword section_size = 0;
10787
10788 //section id
10789
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10790 {
10791 new_return(1);
10792 }
10793
10794 //section version info
10795
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10796 {
10797 new_return(2);
10798 }
10799
10800
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10801 {
10802 new_return(3);
10803 }
10804
10805
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10806 {
10807 18 fake_pack_writing=(writecycle==0);
10808
10809 //section size
10810
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10811 {
10812 new_return(4);
10813 }
10814
10815 18 writesize=0;
10816
10817 //finally... section data
10818
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10819 {
10820 new_return(5);
10821 }
10822
10823
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10824 {
10825
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10826 {
10827
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10828 {
10829 new_return(6);
10830 }
10831
10832
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10833 {
10834 new_return(7);
10835 }
10836
10837
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10838 {
10839 new_return(8);
10840 }
10841
10842
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10843 {
10844 new_return(9);
10845 }
10846
10847
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10848 {
10849 new_return(10);
10850 }
10851
10852
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10853 {
10854 new_return(11);
10855 }
10856
10857
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10858 {
10859 new_return(12);
10860 }
10861
10862 130 byte format = MFORMAT_MIDI;
10863
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10864 {
10865 new_return(13);
10866 }
10867
10868
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10869 130 }
10870 4536 }
10871
10872
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10873 {
10874 9 section_size=writesize;
10875 9 }
10876 18 }
10877
10878
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10879 {
10880 char ebuf[80];
10881 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10882 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10883 }
10884
10885 9 new_return(0);
10886 }
10887
10888 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10889 {
10890 9 dword section_id=ID_CHEATS;
10891 9 dword section_version=V_CHEATS;
10892 9 dword section_size = 0;
10893
10894 //section id
10895
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10896 {
10897 new_return(1);
10898 }
10899
10900 //section version info
10901
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10902 {
10903 new_return(2);
10904 }
10905
10906
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10907 {
10908 new_return(3);
10909 }
10910
10911
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10912 {
10913 18 fake_pack_writing=(writecycle==0);
10914
10915 //section size
10916
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10917 {
10918 new_return(4);
10919 }
10920
10921 18 writesize=0;
10922
10923 //finally... section data
10924
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10925 {
10926 new_return(5);
10927 }
10928
10929
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10930 {
10931
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10932 {
10933 new_return(6);
10934 }
10935
10936
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10937 {
10938 new_return(7);
10939 }
10940 18 }
10941
10942
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10943 {
10944 9 section_size=writesize;
10945 9 }
10946 18 }
10947
10948
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10949 {
10950 char ebuf[80];
10951 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10952 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10953 }
10954
10955 9 new_return(0);
10956 }
10957
10958 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10959 {
10960 //these are here to bypass compiler warnings about unused arguments
10961 9 Header=Header;
10962
10963 9 dword section_id=ID_GUYS;
10964 9 dword section_version=V_GUYS;
10965 9 dword section_size=0;
10966
10967 //section id
10968
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10969 {
10970 new_return(1);
10971 }
10972
10973 //section version info
10974
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10975 {
10976 new_return(2);
10977 }
10978
10979
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10980 {
10981 new_return(3);
10982 }
10983
10984
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10985 {
10986 18 fake_pack_writing=(writecycle==0);
10987
10988 //section size
10989
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10990 {
10991 new_return(4);
10992 }
10993
10994 18 writesize=0;
10995
10996 //finally... section data
10997
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
10998 {
10999
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11000 {
11001 new_return(5);
11002 }
11003 9216 }
11004
11005
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11006 {
11007 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11008 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11009
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11010 {
11011 new_return(6);
11012 }
11013
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11014 {
11015 new_return(7);
11016 }
11017
11018
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11019 {
11020 new_return(8);
11021 }
11022
11023
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11024 {
11025 new_return(9);
11026 }
11027
11028
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11029 {
11030 new_return(10);
11031 }
11032
11033
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11034 {
11035 new_return(11);
11036 }
11037
11038
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11039 {
11040 new_return(12);
11041 }
11042
11043
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11044 {
11045 new_return(13);
11046 }
11047
11048
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11049 {
11050 new_return(14);
11051 }
11052
11053
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11054 {
11055 new_return(15);
11056 }
11057
11058
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11059 {
11060 new_return(16);
11061 }
11062
11063
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11064 {
11065 new_return(17);
11066 }
11067
11068
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].family,f))
11069 {
11070 new_return(18);
11071 }
11072
11073
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11074 {
11075 new_return(19);
11076 }
11077
11078
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11079 {
11080 new_return(20);
11081 }
11082
11083
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11084 {
11085 new_return(21);
11086 }
11087
11088
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11089 {
11090 new_return(22);
11091 }
11092
11093
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11094 {
11095 new_return(23);
11096 }
11097
11098
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11099 {
11100 new_return(24);
11101 }
11102
11103
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11104 {
11105 new_return(25);
11106 }
11107
11108
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11109 {
11110 new_return(26);
11111 }
11112
11113
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11114 {
11115 new_return(27);
11116 }
11117
11118
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11119 {
11120 new_return(28);
11121 }
11122
11123
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11124 {
11125 new_return(29);
11126 }
11127
11128
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11129 {
11130 new_return(30);
11131 }
11132
11133
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11134 {
11135 new_return(31);
11136 }
11137
11138
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11139 {
11140 new_return(32);
11141 }
11142
11143
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11144 {
11145 new_return(33);
11146 }
11147
11148
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11149 {
11150 new_return(34);
11151 }
11152
11153
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11154 {
11155 new_return(35);
11156 }
11157
11158
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11159 {
11160 new_return(36);
11161 }
11162
11163
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11164 {
11165 new_return(37);
11166 }
11167
11168
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11169 {
11170 new_return(38);
11171 }
11172
11173
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11174 {
11175 new_return(39);
11176 }
11177
11178
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11179 {
11180 new_return(40);
11181 }
11182
11183
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11184 {
11185 new_return(41);
11186 }
11187
11188
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11189 {
11190 new_return(42);
11191 }
11192
11193
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11194 {
11195 new_return(43);
11196 }
11197
11198
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11199 {
11200 new_return(44);
11201 }
11202
11203
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11204 {
11205 new_return(45);
11206 }
11207
11208
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11209 {
11210
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11211 {
11212 new_return(46);
11213 }
11214 175104 }
11215
11216
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11217 {
11218 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11220 //Force SFX_HIT here.
11221
11222 2048 }
11223
11224
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11225 {
11226 new_return(47);
11227 }
11228
11229
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11230 {
11231 new_return(48);
11232 }
11233
11234
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11235 {
11236 new_return(49);
11237 }
11238
11239
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11240 {
11241 new_return(50);
11242 }
11243
11244 //New 2.6 defences
11245
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11246 {
11247
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11248 {
11249 new_return(51);
11250 }
11251 202752 }
11252
11253 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11254
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11255 {
11256 new_return(52);
11257 }
11258
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11259 {
11260 new_return(53);
11261 }
11262
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11263 {
11264 new_return(54);
11265 }
11266
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11267 {
11268 new_return(55);
11269 }
11270
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11271 {
11272 new_return(56);
11273 }
11274 // These are not fixed types, but ints, so they are safe to use here.
11275
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11276 {
11277 new_return(57);
11278 }
11279
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11280 {
11281 new_return(58);
11282 }
11283
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11284 {
11285 new_return(59);
11286 }
11287
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11288 {
11289 new_return(60);
11290 }
11291
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11292 {
11293 new_return(61);
11294 }
11295
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11296 {
11297 new_return(62);
11298 }
11299
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11300 {
11301 new_return(63);
11302 }
11303
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11304 {
11305 new_return(64);
11306 }
11307
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11308 {
11309 new_return(65);
11310 }
11311
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11312 {
11313 new_return(66);
11314 }
11315
11316
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11317 {
11318
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11319 {
11320 new_return(67);
11321 }
11322 92160 }
11323
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11324 {
11325 new_return(68);
11326 }
11327 //misc 16->31
11328
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11329 {
11330 new_return(69);
11331 }
11332
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11333 {
11334 new_return(70);
11335 }
11336
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11337 {
11338 new_return(71);
11339 }
11340
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11341 {
11342 new_return(72);
11343 }
11344
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11345 {
11346 new_return(73);
11347 }
11348
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11349 {
11350 new_return(74);
11351 }
11352
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11353 {
11354 new_return(75);
11355 }
11356
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11357 {
11358 new_return(76);
11359 }
11360
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11361 {
11362 new_return(77);
11363 }
11364
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11365 {
11366 new_return(78);
11367 }
11368
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11369 {
11370 new_return(79);
11371 }
11372
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11373 {
11374 new_return(80);
11375 }
11376
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11377 {
11378 new_return(81);
11379 }
11380
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11381 {
11382 new_return(82);
11383 }
11384
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11385 {
11386 new_return(83);
11387 }
11388
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11389 {
11390 new_return(84);
11391 }
11392
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11393 {
11394 new_return(85);
11395 }
11396
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11397 {
11398
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11399 {
11400 new_return(86);
11401 }
11402 294912 }
11403
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11404 {
11405
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11406 {
11407 new_return(87);
11408 }
11409 294912 }
11410
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11411 {
11412 new_return(88);
11413 }
11414
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11415 {
11416
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11417 {
11418 new_return(89);
11419 }
11420 73728 }
11421
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11422 {
11423
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11424 {
11425 new_return(90);
11426 }
11427 18432 }
11428
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11429 {
11430 new_return(91);
11431 }
11432 //somehow forgot these in the older builds -Z
11433
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11434 {
11435 new_return(92);
11436 }
11437
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11438 {
11439 new_return(93);
11440 }
11441
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11442 {
11443 new_return(94);
11444 }
11445
11446 //Enemy Editor InitD[] labels
11447
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11448 {
11449
2/2
✓ Branch 0 taken 4792320 times.
✓ Branch 1 taken 73728 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11450 {
11451
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11452 {
11453 new_return(95);
11454 }
11455 4792320 }
11456
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11457 {
11458
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].weapon_initD_label[q][w],f))
11459 {
11460 new_return(96);
11461 }
11462 4792320 }
11463 73728 }
11464
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weaponscript,f))
11465 {
11466 new_return(97);
11467 }
11468 //eweapon initD
11469
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11470 {
11471
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].weap_initiald[q],f))
11472 {
11473 new_return(98);
11474 }
11475 73728 }
11476
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11477 new_return(99);
11478
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11479 new_return(100);
11480
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11481 new_return(101);
11482
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11483 new_return(102);
11484
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].wunblockable, f))
11485 new_return(103);
11486
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].wmoveflags, f))
11487 new_return(104);
11488
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weapoverrideFLAGS, f))
11489 new_return(105);
11490
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_tilew, f))
11491 new_return(106);
11492
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_tileh, f))
11493 new_return(107);
11494
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hxsz, f))
11495 new_return(108);
11496
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hysz, f))
11497 new_return(109);
11498
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hzsz, f))
11499 new_return(110);
11500
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hxofs, f))
11501 new_return(111);
11502
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_hyofs, f))
11503 new_return(112);
11504
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_xofs, f))
11505 new_return(113);
11506
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].weap_yofs, f))
11507 new_return(114);
11508
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(guysbuf[i].wstep, f))
11509 new_return(115);
11510
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 9216 times.
55296 for(int32_t q = 0; q < WPNSPR_MAX; ++q)
11511 {
11512
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if (!p_iputw(guysbuf[i].burnsprs[q], f))
11513 new_return(116);
11514
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if (!p_iputw(guysbuf[i].light_rads[q], f))
11515 new_return(117);
11516 46080 }
11517
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11518 new_return(118);
11519 9216 }
11520
11521
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11522 {
11523 9 section_size=writesize;
11524 9 }
11525 18 }
11526
11527
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11528 {
11529 char ebuf[80];
11530 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11531 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11532 }
11533
11534 9 new_return(0);
11535 }
11536
11537 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11538 {
11539 //these are here to bypass compiler warnings about unused arguments
11540 9 Header=Header;
11541
11542 9 dword section_id=ID_HEROSPRITES;
11543 9 dword section_version=V_HEROSPRITES;
11544 9 dword section_size=0;
11545
11546 //section id
11547
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11548 {
11549 new_return(1);
11550 }
11551
11552 //section version info
11553
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11554 {
11555 new_return(2);
11556 }
11557
11558
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11559 {
11560 new_return(3);
11561 }
11562
11563
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11564 {
11565 18 fake_pack_writing=(writecycle==0);
11566
11567 //section size
11568
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11569 {
11570 new_return(4);
11571 }
11572
11573 18 writesize=0;
11574
11575 //finally... section data
11576
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11577 {
11578
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11579 {
11580 new_return(5);
11581 }
11582
11583
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11584 {
11585 new_return(5);
11586 }
11587
11588
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11589 {
11590 new_return(5);
11591 }
11592 72 }
11593
11594
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11595 {
11596
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11597 {
11598 new_return(6);
11599 }
11600
11601
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11602 {
11603 new_return(6);
11604 }
11605
11606
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11607 {
11608 new_return(6);
11609 }
11610 72 }
11611
11612
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11613 {
11614
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11615 {
11616 new_return(7);
11617 }
11618
11619
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11620 {
11621 new_return(7);
11622 }
11623
11624
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11625 {
11626 new_return(7);
11627 }
11628 72 }
11629
11630
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11631 {
11632
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11633 {
11634 new_return(8);
11635 }
11636
11637
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11638 {
11639 new_return(8);
11640 }
11641
11642
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11643 {
11644 new_return(8);
11645 }
11646 72 }
11647
11648
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11649 {
11650
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11651 {
11652 new_return(8);
11653 }
11654
11655
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11656 {
11657 new_return(8);
11658 }
11659
11660
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11661 {
11662 new_return(8);
11663 }
11664 72 }
11665
11666
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11667 {
11668
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11669 {
11670 new_return(9);
11671 }
11672
11673
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11674 {
11675 new_return(9);
11676 }
11677
11678
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11679 {
11680 new_return(9);
11681 }
11682 72 }
11683
11684
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11685 {
11686
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11687 {
11688 new_return(10);
11689 }
11690
11691
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11692 {
11693 new_return(10);
11694 }
11695
11696
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11697 {
11698 new_return(10);
11699 }
11700 72 }
11701
11702
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11703 {
11704 new_return(11);
11705 }
11706
11707
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11708 {
11709 new_return(11);
11710 }
11711
11712
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11713 {
11714 new_return(11);
11715 }
11716
11717
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11718 {
11719
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11720 {
11721
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11722 {
11723 new_return(12);
11724 }
11725
11726
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11727 {
11728 new_return(12);
11729 }
11730
11731
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11732 {
11733 new_return(12);
11734 }
11735 108 }
11736 36 }
11737
11738
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11739 {
11740
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11741 {
11742 new_return(13);
11743 }
11744
11745
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11746 {
11747 new_return(13);
11748 }
11749
11750
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11751 {
11752 new_return(13);
11753 }
11754 72 }
11755
11756
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11757 {
11758
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11759 {
11760 new_return(13);
11761 }
11762
11763
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11764 {
11765 new_return(13);
11766 }
11767
11768
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11769 {
11770 new_return(13);
11771 }
11772 72 }
11773
11774
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11775 {
11776 new_return(14);
11777 }
11778
11779 //{ V_HEROSPRITES >= 7
11780
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11781 {
11782
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11783 new_return(15);
11784
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11785 new_return(15);
11786
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11787 new_return(15);
11788 72 }
11789
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11790 {
11791
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11792 new_return(15);
11793
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11794 new_return(15);
11795
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11796 new_return(15);
11797 72 }
11798
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11799 {
11800
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11801 new_return(15);
11802
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11803 new_return(15);
11804
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11805 new_return(15);
11806 72 }
11807
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11808 {
11809
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11810 new_return(15);
11811
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11812 new_return(15);
11813
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11814 new_return(15);
11815 72 }
11816
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11817 {
11818
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11819 new_return(15);
11820
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11821 new_return(15);
11822
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11823 new_return(15);
11824 72 }
11825
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11826 {
11827
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11828 new_return(15);
11829
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11830 new_return(15);
11831
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11832 new_return(15);
11833 72 }
11834
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11835 {
11836
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11837 new_return(15);
11838
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11839 new_return(15);
11840
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11841 new_return(15);
11842 72 }
11843
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11844 {
11845
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11846 new_return(15);
11847
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11848 new_return(15);
11849
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11850 new_return(15);
11851 72 }
11852
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11853 {
11854
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11855 new_return(15);
11856
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11857 new_return(15);
11858
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11859 new_return(15);
11860
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11861 new_return(15);
11862 72 }
11863
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11864 {
11865
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11866 new_return(15);
11867
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11868 new_return(15);
11869
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11870 new_return(15);
11871 72 }
11872
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11873 {
11874
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11875 new_return(15);
11876
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11877 new_return(15);
11878
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11879 new_return(15);
11880 72 }
11881
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11882 {
11883
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11884 new_return(15);
11885
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11886 new_return(15);
11887
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11888 new_return(15);
11889 72 }
11890
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11891 {
11892
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11893 new_return(15);
11894
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11895 new_return(15);
11896
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11897 new_return(15);
11898 72 }
11899
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11900 {
11901
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11902 new_return(15);
11903
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11904 new_return(15);
11905
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11906 new_return(15);
11907 72 }
11908
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11909 {
11910
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11911 new_return(15);
11912
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11913 new_return(15);
11914
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11915 new_return(15);
11916 72 }
11917
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11918 {
11919
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11920 new_return(15);
11921
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11922 new_return(15);
11923
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11924 new_return(15);
11925 72 }
11926
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11927 {
11928
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11929 new_return(15);
11930
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11931 new_return(15);
11932
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11933 new_return(15);
11934 72 }
11935
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11936 {
11937
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11938 new_return(15);
11939
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11940 new_return(15);
11941
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11942 new_return(15);
11943 72 }
11944
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11945 {
11946
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11947 new_return(15);
11948
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11949 new_return(15);
11950
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11951 new_return(15);
11952 72 }
11953
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11954 {
11955
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11956 new_return(15);
11957
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11958 new_return(15);
11959
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11960 new_return(15);
11961 72 }
11962
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11963 {
11964
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11965 new_return(15);
11966
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11967 new_return(15);
11968
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11969 new_return(15);
11970 72 }
11971
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11972 {
11973
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11974 new_return(15);
11975
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11976 new_return(15);
11977
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11978 new_return(15);
11979 72 }
11980
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11981 {
11982
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11983 new_return(15);
11984
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11985 new_return(15);
11986
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11987 new_return(15);
11988 72 }
11989
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11990 {
11991
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11992 new_return(15);
11993
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11994 new_return(15);
11995
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
11996 new_return(15);
11997 54 }
11998
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11999 {
12000
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
12001 new_return(16);
12002
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
12003 new_return(16);
12004
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
12005 new_return(16);
12006 72 }
12007
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12008 {
12009
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
12010 new_return(17);
12011
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
12012 new_return(17);
12013
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
12014 new_return(17);
12015 72 }
12016
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12017 {
12018
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
12019 new_return(17);
12020
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
12021 new_return(17);
12022
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
12023 new_return(17);
12024 72 }
12025
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12026 {
12027
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12028 new_return(17);
12029
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12030 new_return(17);
12031
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12032 new_return(17);
12033 72 }
12034
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12035 {
12036
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12037 new_return(18);
12038
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12039 new_return(18);
12040
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12041 new_return(18);
12042 72 }
12043
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12044 {
12045
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12046 new_return(19);
12047 72 }
12048
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12049 {
12050
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12051 new_return(20);
12052
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12053 new_return(20);
12054
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12055 new_return(20);
12056 54 }
12057
12058
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12059 {
12060 new_return(21);
12061 }
12062
12063
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12064 {
12065 new_return(21);
12066 }
12067
12068
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12069 {
12070 new_return(21);
12071 }
12072
12073
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12074 {
12075
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12076 new_return(22);
12077
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12078 new_return(22);
12079
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12080 new_return(22);
12081 72 }
12082
12083
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12084 {
12085
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12086 {
12087 new_return(23);
12088 }
12089
12090
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12091 {
12092 new_return(23);
12093 }
12094
12095
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12096 {
12097 new_return(23);
12098 }
12099 72 }
12100
12101
12102
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12103 {
12104
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defence[q], f))
12105 new_return(15);
12106 2628 }
12107 //}
12108
12109
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12110 {
12111 9 section_size=writesize;
12112 9 }
12113 18 }
12114
12115 //More data will come here
12116
12117
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12118 {
12119 char ebuf[80];
12120 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12121 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12122 }
12123
12124 9 new_return(0);
12125 }
12126
12127 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12128 {
12129 9 dword section_id=ID_SUBSCREEN;
12130 9 dword section_version=V_SUBSCREEN;
12131 9 dword section_size=0;
12132
12133 //section id
12134
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12135 {
12136 new_return(1);
12137 }
12138
12139 //section version info
12140
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12141 {
12142 new_return(2);
12143 }
12144
12145
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12146 {
12147 new_return(3);
12148 }
12149
12150
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12151 {
12152 18 fake_pack_writing=(writecycle==0);
12153
12154 //section size
12155
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12156 {
12157 new_return(4);
12158 }
12159
12160 18 writesize=0;
12161
12162 18 byte sz = subscreens_active.size();
12163
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12164 new_return(5);
12165
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12166 {
12167 86 int32_t ret = subscreens_active[i].write(f);
12168 86 fake_pack_writing=(writecycle==0);
12169
12170
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12171 new_return(ret);
12172 86 }
12173
12174 18 sz = subscreens_passive.size();
12175
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12176 new_return(5);
12177
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12178 {
12179 64 int32_t ret = subscreens_passive[i].write(f);
12180 64 fake_pack_writing=(writecycle==0);
12181
12182
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12183 new_return(ret);
12184 64 }
12185
12186 18 sz = subscreens_overlay.size();
12187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12188 new_return(5);
12189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12190 {
12191 int32_t ret = subscreens_overlay[i].write(f);
12192 fake_pack_writing=(writecycle==0);
12193
12194 if(ret!=0)
12195 new_return(ret);
12196 }
12197
12198
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12199 {
12200 9 section_size=writesize;
12201 9 }
12202 18 }
12203
12204
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12205 {
12206 char ebuf[80];
12207 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12208 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12209 }
12210
12211 9 new_return(0);
12212 9 }
12213
12214 extern script_data *ffscripts[NUMSCRIPTFFC];
12215 extern script_data *itemscripts[NUMSCRIPTITEM];
12216 extern script_data *guyscripts[NUMSCRIPTGUYS];
12217 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12218 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12219 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12220 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12221 extern script_data *playerscripts[NUMSCRIPTHERO];
12222 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12223 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12224 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12225 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12226 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12227
12228 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12229 {
12230
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12231 3 return writeffscript_old(f, Header);
12232
12233 6 dword section_id = ID_FFSCRIPT;
12234 6 dword section_version = V_FFSCRIPT;
12235 6 dword section_size = 0;
12236 6 dword zasmmeta_version = METADATA_V;
12237 6 byte numscripts = 0;
12238 6 numscripts = numscripts; //to avoid unused variables warnings
12239
12240 //section id
12241
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12242 {
12243 new_return(1);
12244 }
12245
12246 //section version info
12247
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12248 {
12249 new_return(2);
12250 }
12251
12252
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12253 {
12254 new_return(3);
12255 }
12256
12257
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12258 {
12259 new_return(4);
12260 }
12261
12262
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12263 {
12264 12 fake_pack_writing=(writecycle==0);
12265
12266 //section size
12267
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12268 {
12269 new_return(5);
12270 }
12271
12272 12 writesize=0;
12273
12274 12 write_quest_zasm(f);
12275
12276
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12277 {
12278 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12279
12280
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12281 {
12282 new_return(ret);
12283 }
12284 6144 }
12285
12286
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12287 {
12288 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12289
12290
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12291 {
12292 new_return(ret);
12293 }
12294 3072 }
12295
12296
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12297 {
12298 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12299
12300
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12301 {
12302 new_return(ret);
12303 }
12304 3072 }
12305
12306
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12307
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12308 {
12309 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12310
12311
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12312 {
12313 new_return(ret);
12314 }
12315 3072 }
12316
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12317
12318
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12319 {
12320 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12321
12322
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12323 {
12324 new_return(ret);
12325 }
12326 3072 }
12327
12328
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12329 {
12330 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12331
12332
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12333 {
12334 new_return(ret);
12335 }
12336 96 }
12337
12338
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12339 {
12340 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12341
12342
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12343 {
12344 new_return(ret);
12345 }
12346 60 }
12347
12348
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12349 {
12350 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12351
12352
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12353 {
12354 new_return(ret);
12355 }
12356 3072 }
12357
12358
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12359 {
12360 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12361
12362
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12363 {
12364 new_return(ret);
12365 }
12366 3072 }
12367
12368
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12369 {
12370 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12371
12372
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12373 {
12374 new_return(ret);
12375 }
12376 3072 }
12377
12378
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12379 {
12380 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12381
12382
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12383 {
12384 new_return(ret);
12385 }
12386 3072 }
12387
12388
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12389 {
12390 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12391
12392
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12393 {
12394 new_return(ret);
12395 }
12396 6144 }
12397
12398
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12399 {
12400 new_return(2000);
12401 }
12402
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12403 {
12404 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12405
12406
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12407 {
12408 new_return(ret);
12409 }
12410 6144 }
12411
12412
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12413 {
12414 new_return(2001);
12415 }
12416
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12417 {
12418 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12419
12420
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12421 {
12422 new_return(ret);
12423 }
12424 3072 }
12425
12426
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12427 {
12428 new_return(2001);
12429 }
12430
12431
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12432 {
12433 new_return(2002);
12434 }
12435
12436 12 word numffcbindings=0;
12437
12438
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12439 {
12440
2/2
✓ Branch 0 taken 5984 times.
✓ Branch 1 taken 148 times.
6132 if(it->second.scriptname != "")
12441 {
12442 148 numffcbindings++;
12443 148 }
12444 6132 }
12445
12446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12447 {
12448 new_return(2003);
12449 }
12450
12451
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12452 {
12453
2/2
✓ Branch 0 taken 5984 times.
✓ Branch 1 taken 148 times.
6132 if(it->second.scriptname != "")
12454 {
12455
1/2
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
148 if(!p_iputw(it->first,f))
12456 {
12457 new_return(2004);
12458 }
12459
12460
1/2
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
148 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12461 {
12462 new_return(2005);
12463 }
12464
12465
1/2
✓ Branch 0 taken 148 times.
✗ Branch 1 not taken.
148 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12466 {
12467 new_return(2006);
12468 }
12469 148 }
12470 6132 }
12471
12472 12 word numglobalbindings=0;
12473
12474
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12475 {
12476
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12477 {
12478 22 numglobalbindings++;
12479 22 }
12480 96 }
12481
12482
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12483 {
12484 new_return(2007);
12485 }
12486
12487
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12488 {
12489
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12490 {
12491
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12492 {
12493 new_return(2008);
12494 }
12495
12496
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12497 {
12498 new_return(2009);
12499 }
12500
12501
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12502 {
12503 new_return(2010);
12504 }
12505 22 }
12506 96 }
12507
12508 12 word numitembindings=0;
12509
12510
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12511 {
12512
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12513 {
12514 26 numitembindings++;
12515 26 }
12516 3060 }
12517
12518
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12519 {
12520 new_return(2011);
12521 }
12522
12523
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12524 {
12525
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12526 {
12527
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12528 {
12529 new_return(2012);
12530 }
12531
12532
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12533 {
12534 new_return(2013);
12535 }
12536
12537
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12538 {
12539 new_return(2014);
12540 }
12541 26 }
12542 3060 }
12543
12544 //new script types
12545 //npc scripts
12546 12 word numnpcbindings=0;
12547
12548
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12549 {
12550
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12551 {
12552 numnpcbindings++;
12553 }
12554 3060 }
12555
12556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12557 {
12558 new_return(2015);
12559 }
12560
12561
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12562 {
12563
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12564 {
12565 if(!p_iputw(it->first,f))
12566 {
12567 new_return(2016);
12568 }
12569
12570 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12571 {
12572 new_return(2017);
12573 }
12574
12575 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12576 {
12577 new_return(2018);
12578 }
12579 }
12580 3060 }
12581
12582 //lweapon
12583
12584 12 word numlwpnbindings=0;
12585
12586
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12587 {
12588
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12589 {
12590 2 numlwpnbindings++;
12591 2 }
12592 3060 }
12593
12594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12595 {
12596 new_return(2019);
12597 }
12598
12599
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12600 {
12601
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12602 {
12603
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12604 {
12605 new_return(2020);
12606 }
12607
12608
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12609 {
12610 new_return(2021);
12611 }
12612
12613
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12614 {
12615 new_return(2022);
12616 }
12617 2 }
12618 3060 }
12619
12620 //////
12621
12622 //eweapon
12623
12624
12625 12 word numewpnbindings=0;
12626
12627
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12628 {
12629
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12630 {
12631 numewpnbindings++;
12632 }
12633 3060 }
12634
12635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12636 {
12637 new_return(2023);
12638 }
12639
12640
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12641 {
12642
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12643 {
12644 if(!p_iputw(it->first,f))
12645 {
12646 new_return(2024);
12647 }
12648
12649 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12650 {
12651 new_return(2025);
12652 }
12653
12654 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12655 {
12656 new_return(2026);
12657 }
12658 }
12659 3060 }
12660
12661 //player scripts
12662 12 word numherobindings=0;
12663
12664
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12665 {
12666
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12667 {
12668 numherobindings++;
12669 }
12670 48 }
12671
12672
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12673 {
12674 new_return(2027);
12675 }
12676
12677
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12678 {
12679
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12680 {
12681 if(!p_iputw(it->first,f))
12682 {
12683 new_return(2028);
12684 }
12685
12686 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12687 {
12688 new_return(2029);
12689 }
12690
12691 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12692 {
12693 new_return(2030);
12694 }
12695 }
12696 48 }
12697
12698 //dmap scripts
12699 12 word numdmapbindings=0;
12700
12701
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12702 {
12703
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12704 {
12705 10 numdmapbindings++;
12706 10 }
12707 3060 }
12708
12709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12710 {
12711 new_return(2031);
12712 }
12713
12714
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12715 {
12716
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12717 {
12718
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12719 {
12720 new_return(2032);
12721 }
12722
12723
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12724 {
12725 new_return(2033);
12726 }
12727
12728
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12729 {
12730 new_return(2034);
12731 }
12732 10 }
12733 3060 }
12734
12735 //screen scripts
12736 12 word numscreenbindings=0;
12737
12738
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12739 {
12740
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12741 {
12742 4 numscreenbindings++;
12743 4 }
12744 3060 }
12745
12746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12747 {
12748 new_return(2035);
12749 }
12750
12751
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12752 {
12753
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12754 {
12755
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12756 {
12757 new_return(2036);
12758 }
12759
12760
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12761 {
12762 new_return(2037);
12763 }
12764
12765
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12766 {
12767 new_return(2038);
12768 }
12769 4 }
12770 3060 }
12771 //item sprite scripts
12772 12 word numitemspritebindings=0;
12773
12774
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12775 {
12776
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12777 {
12778 numitemspritebindings++;
12779 }
12780 3060 }
12781
12782
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12783 {
12784 new_return(2039);
12785 }
12786
12787
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12788 {
12789
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12790 {
12791 if(!p_iputw(it->first,f))
12792 {
12793 new_return(2040);
12794 }
12795
12796 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12797 {
12798 new_return(2041);
12799 }
12800
12801 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12802 {
12803 new_return(2042);
12804 }
12805 }
12806 3060 }
12807
12808 //combo scripts
12809 12 word numcombobindings=0;
12810
12811
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12812 {
12813
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12814 {
12815 numcombobindings++;
12816 }
12817 6132 }
12818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12819 {
12820 new_return(2043);
12821 }
12822
12823
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12824 {
12825
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12826 {
12827 if(!p_iputw(it->first,f))
12828 {
12829 new_return(2044);
12830 }
12831
12832 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12833 {
12834 new_return(2045);
12835 }
12836
12837 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12838 {
12839 new_return(2046);
12840 }
12841 }
12842 6132 }
12843 //subscreen scripts
12844 12 word numgenericbindings=0;
12845
12846
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12847 {
12848
2/2
✓ Branch 0 taken 6102 times.
✓ Branch 1 taken 30 times.
6132 if(it->second.scriptname != "")
12849 {
12850 30 numgenericbindings++;
12851 30 }
12852 6132 }
12853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12854 {
12855 new_return(2043);
12856 }
12857
12858
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12859 {
12860
2/2
✓ Branch 0 taken 6102 times.
✓ Branch 1 taken 30 times.
6132 if(it->second.scriptname != "")
12861 {
12862
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_iputw(it->first,f))
12863 {
12864 new_return(2044);
12865 }
12866
12867
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12868 {
12869 new_return(2045);
12870 }
12871
12872
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12873 {
12874 new_return(2046);
12875 }
12876 30 }
12877 6132 }
12878
12879 //generic scripts
12880 12 word numsubscreenbindings=0;
12881
12882
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12883 {
12884
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12885 {
12886 numsubscreenbindings++;
12887 }
12888 3060 }
12889
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12890 {
12891 new_return(2047);
12892 }
12893
12894
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12895 {
12896
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12897 {
12898 if(!p_iputw(it->first,f))
12899 {
12900 new_return(2048);
12901 }
12902
12903 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12904 {
12905 new_return(2049);
12906 }
12907
12908 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12909 {
12910 new_return(2050);
12911 }
12912 }
12913 3060 }
12914
12915
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12916 {
12917 6 section_size=writesize;
12918 6 }
12919 12 }
12920
12921
12922
12923
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12924 {
12925 char ebuf[80];
12926 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12927 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12928 }
12929
12930 6 new_return(0);
12931 //return 0; //this is just here to stomp the compiler from whining.
12932 //the irony is that it causes an "unreachable code" warning.
12933 9 }
12934
12935 12 int32_t write_quest_zasm(PACKFILE *f)
12936 {
12937 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12938 12 auto& zasm = zasm_scripts[0]->zasm;
12939 12 size_t num_commands = zasm.size();
12940
12941
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12942 new_return(1);
12943
12944
2/2
✓ Branch 0 taken 340176 times.
✓ Branch 1 taken 12 times.
340188 for(int32_t j=0; j<num_commands; j++)
12945 {
12946 340176 auto& zas = zasm[j];
12947
12948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 340176 times.
340176 if(zas.command==0xFFFF)
12949 continue;
12950 else
12951 {
12952
1/2
✓ Branch 0 taken 340176 times.
✗ Branch 1 not taken.
340176 if(!p_iputw(zas.command,f))
12953 new_return(2);
12954
12955
1/2
✓ Branch 0 taken 340176 times.
✗ Branch 1 not taken.
340176 if(!p_iputl(zas.arg1,f))
12956 new_return(3);
12957
12958
1/2
✓ Branch 0 taken 340176 times.
✗ Branch 1 not taken.
340176 if(!p_iputl(zas.arg2,f))
12959 new_return(4);
12960
12961
1/2
✓ Branch 0 taken 340176 times.
✗ Branch 1 not taken.
340176 if(!p_iputl(zas.arg3,f))
12962 new_return(5);
12963
12964 340176 uint32_t sz = 0;
12965
2/2
✓ Branch 0 taken 339502 times.
✓ Branch 1 taken 674 times.
340176 if(zas.strptr)
12966 674 sz = zas.strptr->size();
12967
1/2
✓ Branch 0 taken 340176 times.
✗ Branch 1 not taken.
340176 if(!p_iputl(sz,f))
12968 new_return(6);
12969
2/2
✓ Branch 0 taken 339508 times.
✓ Branch 1 taken 668 times.
340176 if(sz)
12970 {
12971 668 auto& str = *zas.strptr;
12972
2/2
✓ Branch 0 taken 13910 times.
✓ Branch 1 taken 668 times.
14578 for(size_t q = 0; q < sz; ++q)
12973 {
12974
1/2
✓ Branch 0 taken 13910 times.
✗ Branch 1 not taken.
13910 if(!p_putc(str[q],f))
12975 new_return(7);
12976 13910 }
12977 668 }
12978 340176 sz = 0;
12979
2/2
✓ Branch 0 taken 340038 times.
✓ Branch 1 taken 138 times.
340176 if(zas.vecptr)
12980 138 sz = zas.vecptr->size();
12981
1/2
✓ Branch 0 taken 340176 times.
✗ Branch 1 not taken.
340176 if(!p_iputl(sz,f))
12982 new_return(8);
12983
2/2
✓ Branch 0 taken 340038 times.
✓ Branch 1 taken 138 times.
340176 if(sz) //vector found
12984 {
12985 138 auto& vec = *zas.vecptr;
12986
2/2
✓ Branch 0 taken 650 times.
✓ Branch 1 taken 138 times.
788 for(size_t q = 0; q < sz; ++q)
12987 {
12988
1/2
✓ Branch 0 taken 650 times.
✗ Branch 1 not taken.
650 if(!p_iputl(vec[q],f))
12989 new_return(9);
12990 650 }
12991 138 }
12992 }
12993 340176 }
12994 12 return 0;
12995 }
12996
12997 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
12998 {
12999
2/2
✓ Branch 0 taken 46006 times.
✓ Branch 1 taken 230 times.
46236 if (!script->valid())
13000 {
13001
1/2
✓ Branch 0 taken 46006 times.
✗ Branch 1 not taken.
46006 if (!p_putc(0, f))
13002 new_return(-1);
13003 46006 return 0;
13004 }
13005
13006
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if (!p_putc(1, f))
13007 new_return(-1);
13008
13009 230 zasm_meta const& tmeta = script->meta;
13010
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.zasm_v,f))
13011 new_return(1);
13012
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.meta_v,f))
13013 new_return(2);
13014
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.ffscript_v,f))
13015 new_return(3);
13016
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_putc((int)tmeta.script_type,f))
13017 new_return(4);
13018
13019
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(int32_t q = 0; q < 8; ++q)
13020 {
13021
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putcstr(tmeta.run_idens[q],f))
13022 new_return(5);
13023 1840 }
13024
13025
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(int32_t q = 0; q < 8; ++q)
13026
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putc(tmeta.run_types[q],f))
13027 new_return(6);
13028
13029
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_putc(tmeta.flags,f))
13030 new_return(7);
13031
13032
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.compiler_v1,f))
13033 new_return(8);
13034
13035
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.compiler_v2,f))
13036 new_return(9);
13037
13038
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.compiler_v3,f))
13039 new_return(10);
13040
13041
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputw(tmeta.compiler_v4,f))
13042 new_return(11);
13043
13044
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_putcstr(tmeta.script_name,f))
13045 new_return(12);
13046
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_putcstr(tmeta.author,f))
13047 new_return(13);
13048
2/2
✓ Branch 0 taken 2300 times.
✓ Branch 1 taken 230 times.
2530 for(auto q = 0; q < 10; ++q)
13049 {
13050
1/2
✓ Branch 0 taken 2300 times.
✗ Branch 1 not taken.
2300 if(!p_putcstr(tmeta.attributes[q],f))
13051 new_return(14);
13052
1/2
✓ Branch 0 taken 2300 times.
✗ Branch 1 not taken.
2300 if(!p_putwstr(tmeta.attributes_help[q],f))
13053 new_return(15);
13054 2300 }
13055
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(auto q = 0; q < 8; ++q)
13056 {
13057
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putcstr(tmeta.attribytes[q],f))
13058 new_return(16);
13059
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putwstr(tmeta.attribytes_help[q],f))
13060 new_return(17);
13061 1840 }
13062
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(auto q = 0; q < 8; ++q)
13063 {
13064
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putcstr(tmeta.attrishorts[q],f))
13065 new_return(18);
13066
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13067 new_return(19);
13068 1840 }
13069
2/2
✓ Branch 0 taken 3680 times.
✓ Branch 1 taken 230 times.
3910 for(auto q = 0; q < 16; ++q)
13070 {
13071
1/2
✓ Branch 0 taken 3680 times.
✗ Branch 1 not taken.
3680 if(!p_putcstr(tmeta.usrflags[q],f))
13072 new_return(20);
13073
1/2
✓ Branch 0 taken 3680 times.
✗ Branch 1 not taken.
3680 if(!p_putwstr(tmeta.usrflags_help[q],f))
13074 new_return(21);
13075 3680 }
13076
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(auto q = 0; q < 8; ++q)
13077 {
13078
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putcstr(tmeta.initd[q],f))
13079 new_return(22);
13080
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putwstr(tmeta.initd_help[q],f))
13081 new_return(23);
13082 1840 }
13083
2/2
✓ Branch 0 taken 1840 times.
✓ Branch 1 taken 230 times.
2070 for(auto q = 0; q < 8; ++q)
13084 {
13085
1/2
✓ Branch 0 taken 1840 times.
✗ Branch 1 not taken.
1840 if(!p_putc(tmeta.initd_type[q],f))
13086 new_return(24);
13087 1840 }
13088
13089
1/2
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
230 if(!p_iputl(script->pc, f))
13090 new_return(25);
13091
13092
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 230 times.
230 if(!p_iputl(script->end_pc, f))
13093 new_return(26);
13094
13095 230 return 0;
13096 46236 }
13097
13098
13099 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13100 {
13101 3 dword section_id = ID_FFSCRIPT;
13102 3 dword section_version = 26;
13103 3 dword section_cversion = 1;
13104 3 dword section_size = 0;
13105 3 dword zasmmeta_version = 5;
13106 3 byte numscripts = 0;
13107 3 numscripts = numscripts; //to avoid unused variables warnings
13108
13109 //section id
13110
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13111 {
13112 new_return(1);
13113 }
13114
13115 //section version info
13116
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13117 {
13118 new_return(2);
13119 }
13120
13121
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13122 {
13123 new_return(3);
13124 }
13125
13126
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13127 {
13128 new_return(4);
13129 }
13130
13131
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13132 {
13133 6 fake_pack_writing=(writecycle==0);
13134
13135 //section size
13136
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13137 {
13138 new_return(5);
13139 }
13140
13141 6 writesize=0;
13142
13143
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13144 {
13145 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13146 3072 fake_pack_writing=(writecycle==0);
13147
13148
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13149 {
13150 new_return(ret);
13151 }
13152 3072 }
13153
13154
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13155 {
13156 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13157 1536 fake_pack_writing=(writecycle==0);
13158
13159
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13160 {
13161 new_return(ret);
13162 }
13163 1536 }
13164
13165
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13166 {
13167 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13168 1536 fake_pack_writing=(writecycle==0);
13169
13170
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13171 {
13172 new_return(ret);
13173 }
13174 1536 }
13175
13176
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13177
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13178 {
13179 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13180 1536 fake_pack_writing=(writecycle==0);
13181
13182
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13183 {
13184 new_return(ret);
13185 }
13186 1536 }
13187
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13188
13189
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13190 {
13191 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13192 1536 fake_pack_writing=(writecycle==0);
13193
13194
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13195 {
13196 new_return(ret);
13197 }
13198 1536 }
13199
13200
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13201 {
13202 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13203 48 fake_pack_writing=(writecycle==0);
13204
13205
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13206 {
13207 new_return(ret);
13208 }
13209 48 }
13210
13211
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13212 {
13213 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13214 30 fake_pack_writing=(writecycle==0);
13215
13216
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13217 {
13218 new_return(ret);
13219 }
13220 30 }
13221
13222
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13223 {
13224 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13225 1536 fake_pack_writing=(writecycle==0);
13226
13227
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13228 {
13229 new_return(ret);
13230 }
13231 1536 }
13232
13233
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13234 {
13235 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13236 1536 fake_pack_writing=(writecycle==0);
13237
13238
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13239 {
13240 new_return(ret);
13241 }
13242 1536 }
13243
13244
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13245 {
13246 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13247 1536 fake_pack_writing=(writecycle==0);
13248
13249
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13250 {
13251 new_return(ret);
13252 }
13253 1536 }
13254
13255
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13256 {
13257 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13258 1536 fake_pack_writing=(writecycle==0);
13259
13260
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13261 {
13262 new_return(ret);
13263 }
13264 1536 }
13265
13266
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13267 {
13268 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13269 3072 fake_pack_writing=(writecycle==0);
13270
13271
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13272 {
13273 new_return(ret);
13274 }
13275 3072 }
13276
13277
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13278 {
13279 new_return(2000);
13280 }
13281
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13282 {
13283 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13284 3072 fake_pack_writing=(writecycle==0);
13285
13286
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13287 {
13288 new_return(ret);
13289 }
13290 3072 }
13291
13292
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13293 {
13294 new_return(2001);
13295 }
13296
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13297 {
13298 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13299 1536 fake_pack_writing=(writecycle==0);
13300
13301
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13302 {
13303 new_return(ret);
13304 }
13305 1536 }
13306
13307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13308 {
13309 new_return(2001);
13310 }
13311
13312
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13313 {
13314 new_return(2002);
13315 }
13316
13317 6 word numffcbindings=0;
13318
13319
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13320 {
13321
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13322 {
13323 206 numffcbindings++;
13324 206 }
13325 3066 }
13326
13327
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13328 {
13329 new_return(2003);
13330 }
13331
13332
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13333 {
13334
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13335 {
13336
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13337 {
13338 new_return(2004);
13339 }
13340
13341
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13342 {
13343 new_return(2005);
13344 }
13345
13346
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13347 {
13348 new_return(2006);
13349 }
13350 206 }
13351 3066 }
13352
13353 6 word numglobalbindings=0;
13354
13355
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13356 {
13357
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13358 {
13359 18 numglobalbindings++;
13360 18 }
13361 48 }
13362
13363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13364 {
13365 new_return(2007);
13366 }
13367
13368
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13369 {
13370
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13371 {
13372
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13373 {
13374 new_return(2008);
13375 }
13376
13377
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13378 {
13379 new_return(2009);
13380 }
13381
13382
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13383 {
13384 new_return(2010);
13385 }
13386 18 }
13387 48 }
13388
13389 6 word numitembindings=0;
13390
13391
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13392 {
13393
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13394 {
13395 18 numitembindings++;
13396 18 }
13397 1530 }
13398
13399
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13400 {
13401 new_return(2011);
13402 }
13403
13404
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13405 {
13406
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13407 {
13408
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13409 {
13410 new_return(2012);
13411 }
13412
13413
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13414 {
13415 new_return(2013);
13416 }
13417
13418
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13419 {
13420 new_return(2014);
13421 }
13422 18 }
13423 1530 }
13424
13425 //new script types
13426 //npc scripts
13427 6 word numnpcbindings=0;
13428
13429
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13430 {
13431
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13432 {
13433 numnpcbindings++;
13434 }
13435 1530 }
13436
13437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13438 {
13439 new_return(2015);
13440 }
13441
13442
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13443 {
13444
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13445 {
13446 if(!p_iputw(it->first,f))
13447 {
13448 new_return(2016);
13449 }
13450
13451 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13452 {
13453 new_return(2017);
13454 }
13455
13456 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13457 {
13458 new_return(2018);
13459 }
13460 }
13461 1530 }
13462
13463 //lweapon
13464
13465 6 word numlwpnbindings=0;
13466
13467
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13468 {
13469
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13470 {
13471 numlwpnbindings++;
13472 }
13473 1530 }
13474
13475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13476 {
13477 new_return(2019);
13478 }
13479
13480
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13481 {
13482
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13483 {
13484 if(!p_iputw(it->first,f))
13485 {
13486 new_return(2020);
13487 }
13488
13489 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13490 {
13491 new_return(2021);
13492 }
13493
13494 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13495 {
13496 new_return(2022);
13497 }
13498 }
13499 1530 }
13500
13501 //////
13502
13503 //eweapon
13504
13505
13506 6 word numewpnbindings=0;
13507
13508
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13509 {
13510
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13511 {
13512 numewpnbindings++;
13513 }
13514 1530 }
13515
13516
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13517 {
13518 new_return(2023);
13519 }
13520
13521
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13522 {
13523
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13524 {
13525 if(!p_iputw(it->first,f))
13526 {
13527 new_return(2024);
13528 }
13529
13530 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13531 {
13532 new_return(2025);
13533 }
13534
13535 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13536 {
13537 new_return(2026);
13538 }
13539 }
13540 1530 }
13541
13542 //player scripts
13543 6 word numherobindings=0;
13544
13545
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13546 {
13547
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13548 {
13549 2 numherobindings++;
13550 2 }
13551 24 }
13552
13553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13554 {
13555 new_return(2027);
13556 }
13557
13558
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13559 {
13560
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13561 {
13562
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13563 {
13564 new_return(2028);
13565 }
13566
13567
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13568 {
13569 new_return(2029);
13570 }
13571
13572
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13573 {
13574 new_return(2030);
13575 }
13576 2 }
13577 24 }
13578
13579 //dmap scripts
13580 6 word numdmapbindings=0;
13581
13582
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13583 {
13584
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13585 {
13586 numdmapbindings++;
13587 }
13588 1530 }
13589
13590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13591 {
13592 new_return(2031);
13593 }
13594
13595
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13596 {
13597
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13598 {
13599 if(!p_iputw(it->first,f))
13600 {
13601 new_return(2032);
13602 }
13603
13604 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13605 {
13606 new_return(2033);
13607 }
13608
13609 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13610 {
13611 new_return(2034);
13612 }
13613 }
13614 1530 }
13615
13616 //screen scripts
13617 6 word numscreenbindings=0;
13618
13619
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13620 {
13621
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13622 {
13623 14 numscreenbindings++;
13624 14 }
13625 1530 }
13626
13627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13628 {
13629 new_return(2035);
13630 }
13631
13632
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13633 {
13634
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13635 {
13636
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13637 {
13638 new_return(2036);
13639 }
13640
13641
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13642 {
13643 new_return(2037);
13644 }
13645
13646
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13647 {
13648 new_return(2038);
13649 }
13650 14 }
13651 1530 }
13652 //item sprite scripts
13653 6 word numitemspritebindings=0;
13654
13655
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13656 {
13657
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13658 {
13659 numitemspritebindings++;
13660 }
13661 1530 }
13662
13663
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13664 {
13665 new_return(2039);
13666 }
13667
13668
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13669 {
13670
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13671 {
13672 if(!p_iputw(it->first,f))
13673 {
13674 new_return(2040);
13675 }
13676
13677 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13678 {
13679 new_return(2041);
13680 }
13681
13682 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13683 {
13684 new_return(2042);
13685 }
13686 }
13687 1530 }
13688
13689 //combo scripts
13690 6 word numcombobindings=0;
13691
13692
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13693 {
13694
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13695 {
13696 numcombobindings++;
13697 }
13698 3066 }
13699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13700 {
13701 new_return(2043);
13702 }
13703
13704
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13705 {
13706
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13707 {
13708 if(!p_iputw(it->first,f))
13709 {
13710 new_return(2044);
13711 }
13712
13713 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13714 {
13715 new_return(2045);
13716 }
13717
13718 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13719 {
13720 new_return(2046);
13721 }
13722 }
13723 3066 }
13724 //subscreen scripts
13725 6 word numgenericbindings=0;
13726
13727
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13728 {
13729
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13730 {
13731 numgenericbindings++;
13732 }
13733 3066 }
13734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13735 {
13736 new_return(2043);
13737 }
13738
13739
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13740 {
13741
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13742 {
13743 if(!p_iputw(it->first,f))
13744 {
13745 new_return(2044);
13746 }
13747
13748 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13749 {
13750 new_return(2045);
13751 }
13752
13753 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13754 {
13755 new_return(2046);
13756 }
13757 }
13758 3066 }
13759
13760 //generic scripts
13761 6 word numsubscreenbindings=0;
13762
13763
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13764 {
13765
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13766 {
13767 numsubscreenbindings++;
13768 }
13769 1530 }
13770
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13771 {
13772 new_return(2047);
13773 }
13774
13775
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13776 {
13777
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13778 {
13779 if(!p_iputw(it->first,f))
13780 {
13781 new_return(2048);
13782 }
13783
13784 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13785 {
13786 new_return(2049);
13787 }
13788
13789 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13790 {
13791 new_return(2050);
13792 }
13793 }
13794 1530 }
13795
13796
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13797 {
13798 3 section_size=writesize;
13799 3 }
13800 6 }
13801
13802
13803
13804
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13805 {
13806 char ebuf[80];
13807 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13808 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13809 }
13810
13811 3 new_return(0);
13812 //return 0; //this is just here to stomp the compiler from whining.
13813 //the irony is that it causes an "unreachable code" warning.
13814 3 }
13815
13816 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13817 {
13818 //these are here to bypass compiler warnings about unused arguments
13819 23118 Header=Header;
13820 23118 i=i;
13821
13822
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13823
13824
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13825 {
13826 new_return(6);
13827 }
13828
13829 //Metadata
13830 23118 zasm_meta const& tmeta = script->meta;
13831
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13832 {
13833 new_return(7);
13834 }
13835
13836
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13837 {
13838 new_return(8);
13839 }
13840
13841
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13842 {
13843 new_return(9);
13844 }
13845
13846
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13847 {
13848 new_return(10);
13849 }
13850
13851
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13852 {
13853
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13854 new_return(11);
13855 184944 }
13856
13857
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13858 {
13859
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13860 {
13861 new_return(12);
13862 }
13863 184944 }
13864
13865
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13866 {
13867 new_return(13);
13868 }
13869
13870
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13871 {
13872 new_return(14);
13873 }
13874
13875
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13876 {
13877 new_return(15);
13878 }
13879
13880
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13881 {
13882 new_return(16);
13883 }
13884
13885
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13886 {
13887 new_return(17);
13888 }
13889
13890
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13891 new_return(18);
13892
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13893 new_return(19);
13894
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13895 {
13896
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13897 new_return(27);
13898
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13899 new_return(28);
13900 231180 }
13901
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13902 {
13903
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13904 new_return(29);
13905
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13906 new_return(30);
13907 184944 }
13908
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13909 {
13910
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13911 new_return(31);
13912
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13913 new_return(32);
13914 184944 }
13915
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13916 {
13917
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13918 new_return(33);
13919
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13920 new_return(34);
13921 369888 }
13922
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13923 {
13924
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13925 new_return(35);
13926
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13927 new_return(36);
13928 184944 }
13929
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13930 {
13931
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13932 new_return(37);
13933 184944 }
13934
13935
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13936 {
13937 2056888 auto& zas = script->zasm_script->zasm[j];
13938
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13939 {
13940 new_return(20);
13941 }
13942
13943
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13944 {
13945 11830 break;
13946 }
13947 else
13948 {
13949
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13950 {
13951 new_return(21);
13952 }
13953
13954
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13955 {
13956 new_return(22);
13957 }
13958
13959
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13960 {
13961 new_return(23);
13962 }
13963
13964 2045058 uint32_t sz = 0;
13965
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
13966 2340 sz = zas.strptr->size();
13967
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13968 {
13969 new_return(23);
13970 }
13971
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13972 {
13973 2340 auto& str = *zas.strptr;
13974
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13975 {
13976
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13977 {
13978 new_return(24);
13979 }
13980 214720 }
13981 2340 }
13982 2045058 sz = 0;
13983
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13984 22 sz = zas.vecptr->size();
13985
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13986 {
13987 new_return(25);
13988 }
13989
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13990 {
13991 22 auto& vec = *zas.vecptr;
13992
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13993 {
13994
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13995 {
13996 new_return(26);
13997 }
13998 352 }
13999 22 }
14000 }
14001 2045058 }
14002
14003 23118 new_return(0);
14004 }
14005
14006 extern SAMPLE customsfxdata[WAV_COUNT];
14007 extern uint8_t customsfxflag[WAV_COUNT>>3];
14008
14009 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
14010 {
14011 //these are here to bypass compiler warnings about unused arguments
14012 9 Header=Header;
14013
14014 9 dword section_id=ID_SFX;
14015 9 dword section_version=V_SFX;
14016 9 dword section_size=0;
14017
14018 //section id
14019
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14020 {
14021 new_return(1);
14022 }
14023
14024 //section version info
14025
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14026 {
14027 new_return(2);
14028 }
14029
14030
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14031 {
14032 new_return(3);
14033 }
14034
14035
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14036 {
14037 18 fake_pack_writing=(writecycle==0);
14038
14039 //section size
14040
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14041 {
14042 new_return(4);
14043 }
14044
14045 18 writesize=0;
14046
14047
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14048 {
14049
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14050 {
14051 new_return(5);
14052 }
14053 576 }
14054
14055
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14056 {
14057
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14058 3330 continue;
14059
14060
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14061 {
14062 new_return(5);
14063 }
14064 1260 }
14065
14066
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14067 {
14068
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14069 3330 continue;
14070
14071
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14072 {
14073 new_return(5);
14074 }
14075
14076
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14077 {
14078 new_return(6);
14079 }
14080
14081
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14082 {
14083 new_return(7);
14084 }
14085
14086
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14087 {
14088 new_return(8);
14089 }
14090
14091
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14092 {
14093 new_return(9);
14094 }
14095
14096
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14097 {
14098 new_return(10);
14099 }
14100
14101
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14102 {
14103 new_return(11);
14104 }
14105
14106
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14107 {
14108 new_return(12);
14109 }
14110
14111 //de-endianfy the data
14112 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14113
14114
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14115 {
14116
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14117 {
14118 new_return(13);
14119 }
14120 28596352 }
14121 1260 }
14122
14123
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14124 {
14125 9 section_size=writesize;
14126 9 }
14127 18 }
14128
14129
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14130 {
14131 char ebuf[80];
14132 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14133 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14134 }
14135
14136 9 new_return(0);
14137 }
14138
14139 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14140 {
14141 9 dword section_id=ID_INITDATA;
14142 9 dword section_version=V_INITDATA;
14143 9 dword section_size = 0;
14144
14145 9 zinit.last_map=Map.getCurrMap();
14146 9 zinit.last_screen=Map.getCurrScr();
14147 9 zinit.normalize();
14148
14149 //section id
14150
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14151 {
14152 new_return(1);
14153 }
14154
14155 //section version info
14156
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14157 {
14158 new_return(2);
14159 }
14160
14161
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14162 {
14163 new_return(3);
14164 }
14165
14166 //TODO
14167
14168
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14169 {
14170 18 fake_pack_writing=(writecycle==0);
14171
14172 //section size
14173
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14174 new_return(4);
14175
14176 18 writesize=0;
14177
14178
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14179
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14180 new_return(5);
14181
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(int q = 0; q < MAXLEVELS/8; ++q)
14182 {
14183
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(zinit.map[q], f))
14184 new_return(6);
14185
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(zinit.compass[q], f))
14186 new_return(7);
14187
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(zinit.boss_key[q], f))
14188 new_return(8);
14189
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if(!p_putc(zinit.mcguffin[q], f))
14190 new_return(9);
14191 1152 }
14192
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14193 new_return(10);
14194
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14195 new_return(11);
14196
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14197
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14198 new_return(12);
14199
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14200
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14201 new_return(13);
14202
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14203 new_return(14);
14204
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14205 new_return(15);
14206
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14207 new_return(16);
14208
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14209 new_return(17);
14210
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14211 new_return(18);
14212
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14213 new_return(19);
14214
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14215 new_return(20);
14216
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14217 new_return(21);
14218
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14219 new_return(22);
14220
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14221 new_return(23);
14222
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14223 new_return(24);
14224
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14225 new_return(25);
14226
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14227 new_return(26);
14228
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14229 new_return(27);
14230
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14231 new_return(28);
14232
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14233 new_return(29);
14234
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14235 new_return(30);
14236
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14237 new_return(31);
14238
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14239 new_return(32);
14240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14241 new_return(33);
14242
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14243 new_return(34);
14244
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14245 new_return(35);
14246
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14247 new_return(36);
14248
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14249 new_return(37);
14250
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14251 new_return(38);
14252
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14253 new_return(39);
14254
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14255 new_return(40);
14256
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14257 new_return(41);
14258
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14259 new_return(42);
14260
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14261 new_return(43);
14262
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14263 new_return(44);
14264
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14265 new_return(45);
14266
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14267 new_return(46);
14268
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14269 new_return(47);
14270
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14271 new_return(48);
14272
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14273 new_return(49);
14274
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14275 new_return(50);
14276
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14277 new_return(51);
14278
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14279 new_return(52);
14280
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14281 new_return(53);
14282
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14283 new_return(54);
14284
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14285 new_return(55);
14286
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14287 new_return(56);
14288
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14289 new_return(57);
14290
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14291 new_return(58);
14292
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14293 new_return(59);
14294
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14295 new_return(60);
14296
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14297 new_return(61);
14298
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14299 new_return(62);
14300
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14301 new_return(63);
14302
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14303 new_return(64);
14304
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14305 new_return(65);
14306
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14307 new_return(66);
14308
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14309 new_return(67);
14310
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14311 new_return(68);
14312
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14313 new_return(69);
14314
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14315 new_return(70);
14316
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14317 new_return(71);
14318
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14319 new_return(72);
14320
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14321 new_return(73);
14322
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14323 new_return(74);
14324
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14325 new_return(75);
14326
14327
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14328 {
14329 9 section_size=writesize;
14330 9 }
14331 18 }
14332
14333
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14334 {
14335 char ebuf[80];
14336 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14337 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14338 }
14339
14340 9 new_return(0);
14341 }
14342
14343 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14344 {
14345 //these are here to bypass compiler warnings about unused arguments
14346 9 Header=Header;
14347
14348 9 dword section_id=ID_ITEMDROPSETS;
14349 9 dword section_version=V_ITEMDROPSETS;
14350 // dword section_size=0;
14351 9 dword section_size = 0;
14352 9 word num_item_drop_sets=count_item_drop_sets();
14353
14354 //section id
14355
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14356 {
14357 new_return(1);
14358 }
14359
14360 //section version info
14361
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14362 {
14363 new_return(2);
14364 }
14365
14366
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14367 {
14368 new_return(3);
14369 }
14370
14371
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14372 {
14373 18 fake_pack_writing=(writecycle==0);
14374
14375 //section size
14376
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14377 {
14378 new_return(4);
14379 }
14380
14381 18 writesize=0;
14382
14383 //finally... section data
14384
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14385 {
14386 new_return(5);
14387 }
14388
14389
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14390 {
14391
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14392 {
14393 new_return(6);
14394 }
14395
14396
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14397 {
14398
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14399 {
14400 new_return(7);
14401 }
14402 2360 }
14403
14404
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14405 {
14406
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14407 {
14408 new_return(8);
14409 }
14410 2596 }
14411 236 }
14412
14413
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14414 {
14415 9 section_size=writesize;
14416 9 }
14417 18 }
14418
14419
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14420 {
14421 char ebuf[80];
14422 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14423 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14424 }
14425
14426 9 new_return(0);
14427 }
14428
14429 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14430 {
14431 9 dword section_id=ID_FAVORITES;
14432 9 dword section_version=V_FAVORITES;
14433 9 dword section_size = 0;
14434
14435 //section id
14436
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14437 {
14438 new_return(1);
14439 }
14440
14441 //section version info
14442
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14443 {
14444 new_return(2);
14445 }
14446
14447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14448 {
14449 new_return(3);
14450 }
14451
14452
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14453 {
14454 18 fake_pack_writing=(writecycle==0);
14455
14456 //section size
14457
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14458 new_return(4);
14459
14460 18 writesize=0;
14461
14462
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14463 new_return(16);
14464
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14465 new_return(17);
14466
14467 18 word favcmb_cnt = 0;
14468
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14469
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14470 {
14471 14 favcmb_cnt = q+1;
14472 14 break;
14473 }
14474
14475
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14476 new_return(5);
14477
14478
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14479 {
14480
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14481 new_return(6);
14482
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14483 new_return(7);
14484 460 }
14485
14486
14487 18 word max_combo_cols = MAX_COMBO_COLS;
14488
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14489 new_return(9);
14490
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14491 {
14492
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14493 new_return(10);
14494
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14495 new_return(11);
14496
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14497 new_return(12);
14498 72 }
14499 18 word max_mappages = MAX_MAPPAGE_BTNS;
14500
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14501 new_return(13);
14502
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14503 {
14504
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14505 new_return(14);
14506
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14507 new_return(15);
14508 162 }
14509
14510
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14511 {
14512 9 section_size=writesize;
14513 9 }
14514 18 }
14515
14516
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14517 {
14518 char ebuf[80];
14519 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14520 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14521 }
14522
14523 9 new_return(0);
14524 }
14525
14526 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14527 {
14528
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14529 9 reset_combo_animations();
14530 9 reset_combo_animations2();
14531 9 strcpy(header.id_str,QH_NEWIDSTR);
14532 9 header.zelda_version = ZELDA_VERSION;
14533 9 header.internal = INTERNAL_VERSION;
14534 9 header.data_flags[ZQ_TILES] = true;
14535 9 header.data_flags[ZQ_CHEATS2] = 1;
14536 9 header.build=VERSION_BUILD;
14537
14538
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14539 {
14540 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14541 2268 }
14542
14543 char zinfofilename[2048];
14544 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14545
14546 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14547 9 box_out("Saving Quest...");
14548 9 box_eol();
14549 9 box_eol();
14550
14551
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14552
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14553
14554
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14555 return 1;
14556
14557
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14558
14559
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14560 return 2;
14561
14562
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14563
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14564
14565
14566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14567 {
14568 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14569
14570 box_out("Writing ZInfo...");
14571 if(inf)
14572 {
14573 if(writezinfo(inf,ZI)!=0)
14574 return 2;
14575
14576 pack_fclose(inf);
14577 box_out("okay.");
14578 }
14579 else box_out(" ...file failure");
14580 box_eol();
14581 }
14582 else
14583 {
14584
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14585
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14586 return 2;
14587
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14588
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14589 }
14590
14591
14592
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14593
14594
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14595 return 3;
14596
14597
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14598
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14599
14600
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14601
14602
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14603 return 4;
14604
14605
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14606
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14607
14608
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14609
14610
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14611 return 5;
14612
14613
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14614
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14615
14616
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14617
14618
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14619 return 6;
14620
14621
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14622
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14623
14624
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14625
14626
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14627 return 7;
14628
14629
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14630
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14631
14632
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14633
14634
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14635 return 8;
14636
14637
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14638
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14639
14640
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14641
14642
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14643 return 9;
14644
14645
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14646
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14647
14648
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14649
14650
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14651 return 10;
14652
14653
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14654
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14655
14656
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14657
14658
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14659 return 11;
14660
14661
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14662
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14663
14664
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14665
14666
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14667 return 12;
14668
14669
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14670
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14671
14672
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14673
14674
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14675 return 13;
14676
14677
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14678
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14679
14680
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14681
14682
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14683 return 14;
14684
14685
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14686
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14687
14688
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14689
14690
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14691 return 15;
14692
14693
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14694
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14695
14696
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14697
14698
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14699 return 16;
14700
14701
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14702
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14703
14704
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14705
14706
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14707 return 17;
14708
14709
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14710
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14711
14712
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14713
14714
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14715 return 18;
14716
14717
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14718
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14719
14720
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14721
14722
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14723 return 19;
14724
14725
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14726
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14727
14728
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14729
14730
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14731 return 20;
14732
14733
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14734
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14735
14736
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14737
14738
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14739 return 21;
14740
14741
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14742
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14743
14744
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14745
14746
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14747 return 22;
14748
14749
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14750
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14751
14752
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14753
14754
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14755 return 23;
14756
14757
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14758
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14759
14760
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14761
14762
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14763 return 24;
14764
14765
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14766
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14767
14768
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14769
14770
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14771 return 25;
14772
14773
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14774
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14775
14776
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14777
14778
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14779 return 26;
14780
14781
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14782
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14783
14784
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14785
14786
14787
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14788 {
14789 char const* kfname = filename;
14790 char keyfilename[2048]={0};
14791 zprint2("Writing key files for '%s'\n", kfname, ".zpwd", ".zcheat");
14792
14793 char temp_pw[QSTPWD_LEN] = {0};
14794 uint ind = 0;
14795 for(char const* ext : {"key","zpwd","zcheat"})
14796 {
14797 replace_extension(keyfilename, kfname, ext, 2047);
14798 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14799 char msg[80] = {0};
14800 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14801 msg[78]=13;
14802 msg[79]=10;
14803 pfwrite(msg, 80, fp);
14804 p_iputw(header.zelda_version,fp);
14805 p_putc(header.build,fp);
14806 char const* pwd = header.password;
14807 if(ind == 2) //.zcheat, hashed pwd
14808 {
14809 char hashmap = 'Z';
14810 hashmap += 'Q';
14811 hashmap += 'U';
14812 hashmap += 'E';
14813 hashmap += 'S';
14814 hashmap += 'T';
14815 for ( int q = 0; q < QSTPWD_LEN; ++q )
14816 {
14817 temp_pw[q] = header.password[q];
14818 temp_pw[q] += hashmap;
14819 }
14820 pwd = temp_pw;
14821 }
14822 pfwrite(pwd, strlen(pwd), fp);
14823 pack_fclose(fp);
14824 ++ind;
14825 }
14826 }
14827
14828 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14829 9 std::error_code ec;
14830
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14831
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14832 {
14833 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14834 return ec.value();
14835 }
14836
14837
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14838
14839 #ifdef __EMSCRIPTEN__
14840 em_sync_fs();
14841 #endif
14842
14843 9 return 0;
14844 9 }
14845
14846 // #ifdef _WIN32
14847 // static std::time_t to_time_t(FILETIME const& ft) {
14848 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14849 // t -= 116444736000000000ull;
14850 // t /= 10000000u;
14851 // return static_cast<std::time_t>(t);
14852 // }
14853 // #else
14854 // #endif
14855 template<typename TP>
14856 5 static std::time_t to_time_t(TP tp) {
14857 using namespace std::chrono;
14858 5 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14859 5 return system_clock::to_time_t(sctp);
14860 }
14861
14862 5 std::string get_time_last_modified_string(std::string path)
14863 {
14864
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 auto write_time = fs::last_write_time(path);
14865 // TODO: C++20 but not supported yet.
14866 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14867 5 std::time_t tt = to_time_t(write_time);
14868 5 std::tm *gmt = std::gmtime(&tt);
14869 5 std::stringstream buffer;
14870
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 buffer << std::put_time(gmt, "%Y-%m-%d");
14871
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string formattedFileTime = buffer.str();
14872 5 return formattedFileTime;
14873
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 }
14874
14875 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14876 {
14877 // Always backup quest if it was last saved in a different version of the editor,
14878 // or if this a new file and is overwritting another qst file.
14879
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 5 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14880 {
14881 5 std::string backup_name;
14882
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string last_mod = get_time_last_modified_string(filename);
14883
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (strlen(header.zelda_version_string) > 0)
14884 {
14885
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14886 5 }
14887 else
14888 {
14889 backup_name = fmt::format("{}", last_mod);
14890 }
14891
7/14
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
5 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14892
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 fs::path backup_path = fs::path("backups") / backup_fname;
14893
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (!fs::exists(backup_path))
14894 {
14895
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 fs::create_directories(fs::path("backups"));
14896
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 if (fs::copy_file(filename, backup_path))
14897 {
14898
5/10
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
5 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14899 5 }
14900 else
14901 {
14902 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14903 }
14904 5 }
14905 5 }
14906
14907 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14908 9 fake_pack_writing = false;
14909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14910 {
14911 box_out("-- Error saving quest file! --");
14912 box_end(true);
14913 }
14914 9 else box_end(false);
14915 9 return ret;
14916 }
14917
14918 9 int32_t save_quest(const char *filename, bool timed_save)
14919 {
14920
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14921
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14922 char ext1[5];
14923 9 ext1[0]=0;
14924
14925
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14926 {
14927 sprintf(ext1, "qt");
14928 }
14929 else
14930 {
14931 9 sprintf(ext1, "qb");
14932 }
14933
14934
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14935 {
14936 char backupname[2048];
14937 char backupname2[2048];
14938 char ext[12];
14939
14940 for(int32_t i=retention-1; i>0; --i)
14941 {
14942 sprintf(ext, "%s%d", ext1, i-1);
14943 replace_extension(backupname, filepath, ext, 2047);
14944
14945 if(exists(backupname))
14946 {
14947 sprintf(ext, "%s%d", ext1, i);
14948 replace_extension(backupname2, filepath, ext, 2047);
14949
14950 if(exists(backupname2))
14951 {
14952 remove(backupname2);
14953 }
14954
14955 rename(backupname, backupname2);
14956 }
14957 }
14958
14959 //don't do this if we're not saving to the same name -DD
14960 if(!timed_save && !strcmp(filepath, filename))
14961 {
14962 sprintf(ext, "%s%d", ext1, 0);
14963 replace_extension(backupname, filepath, ext, 2047);
14964 rename(filepath, backupname);
14965 }
14966 }
14967
14968 int32_t ret;
14969 9 ret = save_unencoded_quest(filename, compress, filename);
14970
14971 9 return ret;
14972 }
14973
14974 8 void center_zq_class_dialogs()
14975 {
14976 8 jwin_center_dialog(pwd_dlg);
14977 8 }
14978
14979 void zmap::prv_secrets(bool high16only)
14980 {
14981 mapscr *s = &prvscr;
14982 mapscr *t = prvlayers;
14983 int32_t ft=0;
14984
14985 for(int32_t i=0; i<176; i++)
14986 {
14987 if(!high16only)
14988 {
14989 for(int32_t j=-1; j<6; j++)
14990 {
14991 int32_t newflag = -1;
14992
14993 for(int32_t iter=0; iter<2; ++iter)
14994 {
14995 if(!t[j].valid)
14996 continue;
14997
14998 int32_t checkflag=combobuf[t[j].data[i]].flag;
14999
15000 if(iter==1)
15001 {
15002 checkflag=t[j].sflag[i];
15003 }
15004
15005 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15006 if (ft != -1)
15007 {
15008 if(j==-1)
15009 {
15010 s->data[i] = s->secretcombo[ft];
15011 s->cset[i] = s->secretcset[ft];
15012 newflag = s->secretflag[ft];
15013 }
15014 else
15015 {
15016 t[j].data[i] = t[j].secretcombo[ft];
15017 t[j].cset[i] = t[j].secretcset[ft];
15018 newflag = t[j].secretflag[ft];
15019 }
15020 }
15021 }
15022
15023 if(newflag >-1)
15024 {
15025 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
15026 }
15027 }
15028 }
15029
15030 //if(true)
15031 //{
15032 int32_t newflag = -1;
15033
15034 for(int32_t iter=0; iter<2; ++iter)
15035 {
15036 int32_t checkflag=combobuf[s->data[i]].flag;
15037
15038 if(iter==1)
15039 {
15040 checkflag=s->sflag[i];
15041 }
15042
15043 if((checkflag > 15)&&(checkflag < 32))
15044 {
15045 s->data[i] = s->secretcombo[(checkflag)-16+4];
15046 s->cset[i] = s->secretcset[(checkflag)-16+4];
15047 newflag = s->secretflag[(checkflag)-16+4];
15048 // putit = true;
15049 }
15050 }
15051
15052 if(newflag >-1) s->sflag[i] = newflag;
15053
15054 for(int32_t j=0; j<6; j++)
15055 {
15056 if(!t[j].valid) continue;
15057
15058 int32_t newflag2 = -1;
15059
15060 for(int32_t iter=0; iter<2; ++iter)
15061 {
15062 int32_t checkflag=combobuf[t[j].data[i]].flag;
15063
15064 if(iter==1)
15065 {
15066 checkflag=t[j].sflag[i];
15067 }
15068
15069 if((checkflag > 15)&&(checkflag < 32))
15070 {
15071 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15072 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15073 newflag2 = t[j].secretflag[(checkflag)-16+4];
15074 }
15075 }
15076
15077 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15078 }
15079 }
15080
15081 //FFCs
15082 word num_ffcs = s->numFFC();
15083 for(word i=0; i<num_ffcs; ++i)
15084 {
15085 if(!high16only)
15086 {
15087 for(int32_t iter=0; iter<1; ++iter)
15088 {
15089 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15090
15091 if(iter==1)
15092 {
15093 checkflag=s->sflag[i];
15094 }
15095
15096 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15097 if (ft != -1)
15098 {
15099 s->ffcs[i].data = s->secretcombo[ft];
15100 s->ffcs[i].cset = s->secretcset[ft];
15101 }
15102 }
15103 }
15104
15105 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15106 {
15107 for(int32_t iter=0; iter<1; ++iter)
15108 {
15109 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15110
15111 if(iter==1)
15112 {
15113 // FFCs can't have flags! Yet...
15114 }
15115
15116 if((checkflag > 15)&&(checkflag < 32))
15117 {
15118 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15119 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15120 }
15121 }
15122 }
15123 }
15124 }
15125